【发布时间】:2012-09-20 12:38:11
【问题描述】:
让我的 .htaccess ReWrite 在我的 apache Web 服务器上工作时遇到了很多麻烦。我已经阅读了几个教程并测试了我与 Grep 的正则表达式匹配。
代码如下:
RewriteRule \?action=viewArticle&articleId=([0-9]*)&categoryId=([0-9])$ essays/$1 [R=301,L]
这是我要匹配的网址:
http://mysite.com/?action=viewArticle&articleId=15&categoryId=1
改成
http://mysite.com/essays/15
更新:解决方案!来自乔恩的excellent tutorial。将<base href="/"> 放在头文件中以使css 正常工作非常重要。
最终的重写看起来像这样:
RewriteCond %{THE_REQUEST} /?action=viewArticle&articleId=([0-9]*)&categoryId=([0-9])
RewriteRule ^$ /essays/%1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^essays/([0-9]+) /?action=viewArticle&articleId=$1&categoryId=([0-9]) [L]
【问题讨论】: