我有一个传统网站,我已经添加了WordPress,它安装在/ wp中并重写为root。我还有一个需要重写规则的perl程序。我知道我不应该有两个RewriteBase实例,但是看不到如何让这两个部分一起工作。使用当前设置,当WP部分处于活动状态时,虚拟目录/ amazon将为所有呼叫生成404.
删除第二个重写基不起作用。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
RewriteEngine on
RewriteBase /
RewriteRule ^(amazon)$ $1/ [R]
RewriteRule ^(amazon)/(.*)(\.[a-z]+)$ cgi-bin/cbooks/ca.pl?virtual=$2&virtual.dir=$1 [L]
RewriteRule ^(amazon)/(.*)$ cgi-bin/cbooks/ca.pl?virtual=$2&virtual.dir=$1 [L]
答案 0 :(得分:1)
你应该在你的wordpress路由规则之前加上亚马逊规则,并在规则的目标中添加一个前导斜杠,使它们成为绝对的URL路径:
RewriteEngine on
RewriteRule ^amazon$ /$1/ [R,L]
RewriteRule ^amazon/(.*)(\.[a-z]+)$ /cgi-bin/cbooks/ca.pl?virtual=$2&virtual.dir=$1 [L]
RewriteRule ^amazon/(.*)$ /cgi-bin/cbooks/ca.pl?virtual=$2&virtual.dir=$1 [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
WordPress路由规则正在路由您的亚马逊规则,因为它们首先出现。