Redirect Not Working?

So My problem is that when visiting example.com/members I am redirected to www.example.commembers/ (notice that this is not a valid web address) instead of members.example.com (It only works correctly when there is the www). However, this redirection seems to happen with or without the following htaccess file. What to I need to add/change to stop this problem.

This is my htaccess file located in the members folder:

Read More
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/members/(.*)$ http://members.example.com/$1

Then there is the wordpress htaccess file in the root directory:

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

Related posts

Leave a Reply

1 comment

  1. Problem is in your first rule. Change your code to:

    RewriteEngine On
    RewriteBase /members/
    
    RewriteCond %{HTTP_HOST} !^members. [NC]    
    RewriteRule ^(.*)$ http://members.example.com/$1 [L,R=301,NC]
    
    RewriteCond %{HTTP_HOST} ^example.com$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]