通过apache htaccess RewriteRule搜索并替换部分URL

时间:2014-04-16 11:40:53

标签: php apache .htaccess mod-rewrite url-rewriting

我想重写URL,如:

http://post.local/web/bundles/silverkixcms/elFinder/elfinder.html?CKEditor=silverkix_cmsbundle_pagetype_content&CKEditorFuncNum=1&langCode=en

http://post.local/bundles/silverkixcms/elFinder/elfinder.html?CKEditor=silverkix_cmsbundle_pagetype_content&CKEditorFuncNum=1&langCode=en

意味着“web /”部分应该用“”替换(或删除它),但是我在为.htaccess构建重写规则时遇到了问题。

注意:mod_rewrite已启用(RewriteEngine on)

2 个答案:

答案 0 :(得分:0)

RewriteRule ^web/bundles/(.*) bundles/$1 [QSA]

答案 1 :(得分:0)

这应该有效:

RewriteEngine On
RewriteRule ^web/bundles/(.*) /bundles/$1 [R]

以上内容会从网址中删除web/

http://post.local/web/bundles/silverkixcms/elFinder/elfinder.html?CKEditor=silverkix_cmsbundle_pagetype_content&CKEditorFuncNum=1&langCode=en

将成为

http://post.local/bundles/silverkixcms/elFinder/elfinder.html?CKEditor=silverkix_cmsbundle_pagetype_content&CKEditorFuncNum=1&langCode=en