网址无法正确重写

时间:2014-08-01 07:35:21

标签: regex apache .htaccess mod-rewrite

我有一个网址:

http://example.com/NEW2014/portfolio/project.html?project_name=test

我希望能够重写为:

http://example.com/NEW2014/portfolio/project/test

这就是我正在尝试但我得到500内部服务器错误

RewriteRule ^portfolio/([^/.]*)/?$ /portfolio/project.html?project_name=$1 [L,QSA,NC]

有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

您的规则正在循环,因此会出现500内部错误。要解决此问题,请在/NEW2014/portfolio/.htaccess

中使用此规则
Options -MultiViews
RewriteEngine On
RewriteBase /NEW2014/portfolio/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^project/(.+?)/?$ project.html?project_name=$1 [L,QSA,NC]