问题
I'm looking to use url rewrite to access this...
http://url.com/?a=value
via...
http://url.com/value
So that by using url.com/value I'm actually loading url.com/?a=value.
I'm assuming I need to put a rewrite in an htaccess file and then somehow detect this in index.php and pull out the field value? It's a bit beyond me unfortunately so would really appreciate your help.
Thanks!
回答1:
This is a standard htaccess file for "pretty" urls like the one you need:
#.htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?a=$1 [L]
then in your index.php you can get the initially requested path from the 'a' variable.
$path = $_GET['a'];
回答2:
This .htaccess code takes into consideration something like http://url.com/value?parameter=something
RewriteEngine On
RewriteRule ^([A-Za-z0-9-/]+)\&(.*)$ /$1?$2 [R]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-/_]+)$ /index.php?a=$1&${QUERY_STRING} [L,QSA]
来源:https://stackoverflow.com/questions/8101063/rewrite-url-from-pretty-to-ugly-something-a-somthing