tags:

views:

52

answers:

2

How to get the /2/xxx part in filename.php?

It's not $_GET or $_POST

A: 

You have to turn on mod_rewrite engine. The file.name.php isn't the file that the server will actually execute otherwise.

You would normally get it from the SERVER vars, but you can't do that for what you have because presumably you actually want filename.php to be the loaded script.

Look at this article: http://articles.sitepoint.com/article/guide-url-rewriting

There are lots more out there.

Laykes
I know about the apache configuration part,but don't know how to get what I want in `filename.php`,any tips?
Well, if you use mod rewrite, you make sure its available as a GET var.
Laykes
I know I can get it as a GET var,but that's not necessary,right?
Yeah it is. How else do you expect to run the script filename.php.You have to modrewrite it because otherwise PHP will try and load the script named /XXXX. I wouldn't do what you are doing anyway if I was creating my URLs.
Laykes
Because I've configured apache so that when it detects the requested file does exist,mod-rewrite will ignore,not changing the uri at all.And this is a quite widely used trick.
-1 You don’t need mod_rewrite to get that behavior. `AcceptPathInfo` is part of the core of Apache.
Gumbo
He can't use that because his script that he wants won't execute. Provide an answer to this question so I can -1 you also please.
Laykes
+2  A: 

$_SERVER['PATH_INFO']

Note that AcceptPathInfo must be On for this to work.

Ignacio Vazquez-Abrams
Is it `On` by default in Apache?
As described by the linked page, the default is to let the file handler tell. I'm not sure whether or not `mod_php` enables it by default, but it can't hurt to require it to be on.
Ignacio Vazquez-Abrams