Apache .htaccess mod_rewrite多个RewriteRules

时间:2014-11-07 19:29:59

标签: regex apache .htaccess mod-rewrite redirect

我已将我的网站迁移到wordpress网站,并将永久链接设置为帖子名称。我需要添加一个rewriteRule来从cgi目录中获取任何内容,然后将它们发送到我试过的主页:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
RewriteRule ^cgi(.*)$ http://example.com

从wordpress规则中删除[L]并添加最后一行但它仍然无效。有人能告诉我我做错了什么吗?

1 个答案:

答案 0 :(得分:1)

像以前一样保持L标记,并且cgi规则应放在RewriteBase行以下:

RewriteEngine On
RewriteBase /

RewriteRule ^cgi(.*)$ / [L,NC,R]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]