rewrite rule htaccess - how to get back query sting for usage
Is there is a way to get query string back in PHP?
I have:
http://myweb开发者_StackOverflow社区site.com/cars/BMW/
http://mywebsite.com/List.php?categories=/cars/BMW/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /List.php?categories=$1 [L]
I want to capture categories value in PHP .Please note the parameter format '/cars/BMW/'
You access the value just like you used to so to get the cars value you would just do this.
echo $_GET['categories'];
should echo out
/cars/BMW
You can try the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^categories=(.*)
RewriteRule .* /List.php?categories=$1 [L]
This will capture whatever comes after categories in the query-string and apply it in the rule.
In PHP, access it via $_GET['categories']
, and use the explode()
function to separate the parts on the /
:
if (isset($_GET['categories']))
{
$parts = explode("/", $_GET['categories']);
$vehicle_type = $parts[0];
$vehicle_make = $parts[1];
echo $vehicle_type . " ";
echo $vehicle_make;
}
精彩评论