Reputation: 4058
I have the following htaccess to redirect users from www.mysite.com or http://mysite.com to http://mysite.com/subfolder
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [OR]
RewriteCond %{HTTP_HOST} !^mysite.com$
RewriteRule ^(.*)$ http://mysite.com/subfolder/$1 [L,R=301]
It works perfectly, but for some reason its redirecting to http://www.mysite.com/subfolder/ (I need to remove the www), the subfolder is just a regular Wordpress installation and it has the default .htaccess file, I tried adding the following:
# Redirect
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) http://mysite.com/subfolder/$1 [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /subfolder
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder/index.php [L]
</IfModule>
# END WordPress
To remove the www from the url, but it gives me a bad redirect error, I'm really new with this .htaccess configuration so I don't know what I'm doing wrong.
Can anyone help me? Thanks in advance!
Upvotes: 1
Views: 2001
Reputation: 29965
Of course, you should not redirect the user if he/she is already redirected.
To achieve this, you'll need a RewriteCond
to check whether you are already in the subfolder.
Example:
RewriteCond %{REQUEST_URI} !^/subfolder/
Upvotes: 1