使用PHP将子页面放入变量而不是使用$ _GET [duplicate]

This question already has an answer here:

I am fully versed in how to get, and clean the vars in a $_GET and $_POST, and I understand that $_REQUEST listens for both GET and POST's.

I understand that the GET is www.somesite.com?GET=MYVAR, but my question is this. Can you take: www.somesite.com/MYVAR and put the subpage into a var, as apposed to using the ?GET=MYVAR

In PHP

Thanks,

</div>

Assuming you're using Apache, you would use the mod_rewrite module with an .htaccess file. There are tons of tutorials you can find via Google once you know the right words :)

Yes, but this is actually less dependent on PHP and more dependent on your webserver. It's called rewriting URLs. If you're using Apache, it's mod_rewrite you'll need to look into.

Here's an example for nginx using a rewrite rule:

rewrite ^([^/]+)(/)?$ /index.php?var=$1;

Then you'll be able to access it using

$_GET['var'];

Have you had a look at:

$_SERVER['REQUEST_URI']

and then split it (e.g. explode | preg_split)?

Typically this is done using the mod_rewrite as mentioned in the other answers. But you can also get the url from the $_SERVER variable and parse the resulting string.

http://us3.php.net/manual/en/reserved.variables.server.php