2013-06-23 28 views
1

我试图让这个RewriteRule能够工作,尽管它并没有出于某种奇怪的原因。我想这可能是在%迹象表明真实拧起来:.htaccess有特殊字符的重写规则

http://site.com/c%content_cc%/more-stuff/in/here

RewriteEngine on 
RewriteRule ^c%content_cc%/(.*)$ ccontent_cc/$1 [L] 

我试图把它改写到:http://site.com/ccontent_cc/more-stuff/in/here

当我使用这个工具,并把我的规则,它回来说它应该重写正确。

http://htaccess.madewithlove.be/

回答

0

的问题是浏览器看到URL中%标志往往它在URL encoding用到了。您可以将%字符包装在括号内,并按照字面处理。在这里,我们将从REQUEST_URI中提取它们。

RewriteEngine on 
RewriteCond %{REQUEST_URI} ^/c[%]content_cc[%]/(.*)$ 
RewriteRule ^.* ccontent_cc/%1 [L] 

如果这是一个重定向你应该使用R标志:

RewriteEngine on 
RewriteCond %{REQUEST_URI} ^/c[%]content_cc[%]/(.*)$ 
RewriteRule ^.* ccontent_cc/%1 [R,L] 

如果它是一个永久重定向,你应该使用R=301

RewriteEngine on 
RewriteCond %{REQUEST_URI} ^/c[%]content_cc[%]/(.*)$ 
RewriteRule ^.* ccontent_cc/%1 [R=301,L]