WP is ignoring .htaccess rewritten URL

I have two domains being served from the same WP install. edit: not multi-site

In wp-config.php I have define('WP_SITEURL', "http://$hostname/wordpress"); etc.

Read More

The two domains will have similar content, but we want to be able to have them at the same path, e.g. domain1.com/about-us and domain2.com/about-us.

I’ve therefore set up these two pages dom1about-us and dom2about-us, and in my .htaccess I have:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} dom1 [NC]
RewriteRule ^((about-us|etc).*) /dom1/$1 [NC,QSA,L]

RewriteCond %{HTTP_HOST} dom2 [NC]
RewriteRule ^((about-us|etc).*) /dom2/$1 [NC,QSA,L]

RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I get (edit: WordPress) 404 error pages for the above URLs. I’ve added print_r($_SERVER); in my 404 template and get the following (simplified output).

Array
(
[REQUEST_URI] => /about-us/
[REDIRECT_REDIRECT_STATUS] => 200
[REDIRECT_STATUS] => 200
[HTTP_HOST] => dom1.dev
[SERVER_NAME] => dom1.dev
[REDIRECT_URL] => /dom1/about-us/
[QUERY_STRING] => 
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
...
)

Doesn’t that mean that the rewrite has worked, but WP is not using it?

Many thanks in advance.

Related posts

1 comment

  1. RewriteCond %{HTTP_HOST} dom1 [NC]
    RewriteRule ^((about-us|etc).*) /dom1/$1 [NC,QSA,L]
    

    Your rewrite rule includes the L parameter, which makes it stop processing rewrites. So WordPress’s rules to redirect to index.php likely never come into effect. Which means WordPress is not even being run here. The 404 is likely from the webserver saying that the file at /dom1/about-us does not exist.

Comments are closed.