Multiple RewriteRules

I have a conventional site to which I’ve added WordPress which is installed in /wp and rewritten to root. I also have a perl program which needs a rewrite rule. I understand that I should not have two instances of RewriteBase but cannot see how to get the two sections working together. With the current setup, the virtual directory /amazon results in a 404 for all calls when the WP section is active.

Removing the second rewritebase has no effect.

# 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]

Related posts

Leave a Reply

1 comment

  1. You should put your amazon rules before your wordpress routing rules and add a leading slash to the rule’s target making them absolute URL-paths:

    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
    

    The wordpress routing rules are routing your amazon rules because they come first.