带有 .htaccess 的 SEO 友好 URL [英] SEO friendly URL's with .htaccess
问题描述
有人可以帮我重写一些 URL 吗?
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
并希望它们被请求为:
www.mydomain.com/photos/people
www.mydomain.com/photos/wildlife
我使用的是 IIS,起初我的托管服务提供商使用带有 httpd.ini 文件的 ISAPI_Rewrite,现在他们已经切换到带有 .htaccess 文件的 Helicon Ape.请参阅:http://www.isapirewrite.com/ 和 http://www.helicontech.com/ape/
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/
我尝试了 ISAPI_Rewrite 方式:
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]
但它不起作用.
建议?
推荐答案
试试这个
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 将把照片/wildlife?a=true 重定向到 test/gallery.asp?id=wildlife&a=true
third will redirect photos/wildlife?a=true to test/gallery.asp?id=wildlife&a=true
如果您不想使用 a=true 重定向,只需给出 QSA ;)
if you don't want to redirect with a=true, just give out QSA ;)
这篇关于带有 .htaccess 的 SEO 友好 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!