问题
Can anybody please help me with some URL rewriting?
I have (for example) these pages:
www.mydomain.com/test/gallery.asp?id=2
www.mydomain.com/test/gallery.asp?id=3
and want them to be requested as:
www.mydomain.com/photos/people
www.mydomain.com/photos/wildlife
I'm using IIS and at first my hosting provider was using ISAPI_Rewrite with a httpd.ini file, now they have switched to Helicon Ape with a .htaccess file. See: http://www.isapirewrite.com/ and http://www.helicontech.com/ape/
I tried it the ISAPI_Rewrite way:
RewriteRule /photos/people /test/gallery.asp?id=2 [I,L]
RewriteRule /photos/wildlife /test/gallery.asp?id=3 [I,L]
But it doesn't work.
Suggestions?
回答1:
try this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^photos/(.*)$ test/gallery.asp?id=$1 [L,QSA]
first row is test if it isn't file
second row is test if it isn't directory
third will redirect photos/wildlife?a=true to test/gallery.asp?id=wildlife&a=true
if you don't want to redirect with a=true, just give out QSA ;)
来源:https://stackoverflow.com/questions/4547806/seo-friendly-urls-with-htaccess