In my root domain I have an .htaccess to redirect non-www to the www, and to redirect to a subdirectory (containing a temporary website). This is done using the following code:
Options +FollowSymLinks
RewriteEngine On
# non-www to www, exclude localhost
RewriteCond %{HTTP_HOST} \.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# temp redir to subdir-wordpress
RewriteRule ^$ /subdir [L]
In the subdirectory runs a Wordpress setup using the following .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]
</IfModule>
# END WordPress
What happens is that people get redirected to http://domain.com/subdir
, while I want them to end up at http://www.domain.com/subdir
. I tested with curl and noticed that it redirects with these steps:
- domain.com => www.domain.com
- www.domain.com => www.domain.com/subdir
- www.domain.com/subdir => domain.com/subdir
So the .htaccess in the root dir seems to work fine. But the automated Wordpress .htaccess seems to destroy my hard work :-)
Anyone knows how I can modify the Wordpress .htaccess so it does work?
Its not the Wordpress .htaccess but the Wordpress blog url.
Log into your Wordpress Admin and then goto Settings->General and change your Wordpress URL to www.domain.com/subdir