使用mod_rewrite更改URL中的单词

时间:2012-09-26 04:17:41

标签: .htaccess mod-rewrite

我试图更改单词" portfolio"在我的网址中" portfolio / project"并无意中创建了一个重定向循环。非常感谢帮助我指明正确的方向。

示例:

http://www.example.com/portfolio/interactive/abc/

http://www.example.com/portfolio/project/interactive/abc/

当前的htaccess(最后两行与问题有关):

redirect 301 "/sitemap.xml" http://www.example.com/sitemap.php

RewriteEngine On
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sitemap.php
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_URI} /.*portfolio.*$ [NC]
RewriteRule ^(.*)portfolio(.*)$ /$1portfolio/project$2 [R=301,L]

1 个答案:

答案 0 :(得分:1)

你的问题是你的正则表达式也匹配你的目标,所以在重定向之后,URI匹配相同的规则并再次被重定向(你可能已经注意到URI中有一堆/project/project/project/project/project/project/project

添加排除条件:

RewriteCond %{REQUEST_URI} !portfolio/project
RewriteCond %{REQUEST_URI} /.*portfolio.*$ [NC]
RewriteRule ^(.*)portfolio(.*)$ /$1portfolio/project$2 [R=301,L]
相关问题