Reputation: 1008
I have the subdomain sub.main.com
which is redirected to www.sub.main.com/sub
for some reason, causing a 404.
FWIW, this is what my .htaccess
file looks like in the root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
default wordpress .htaccess
in sub
The solution proposed by @anubhava has fixed the first problem, being that sub.main.com
was redirected to www.sub.main.com/sub
, removing the www
; however, this still redirects to sub.main.com/sub
.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^main\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Upvotes: 1
Views: 32
Reputation: 785156
Keep redirect rule at top and make it target only main domain:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^main\.com$ [NC]
#RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Make sure to clear your browser cache before testing this change.
Removing the www
in the RewriteRule
has solved the issue.
Upvotes: 1