I know that this had been asked numerous times. And I’ve red them all. And I did all that. And it should work. But it doesn’t.
Here’s my configuration:
I have main domain: mydomain.com, a html main website. Within that domain, i have a folder called “app”, like mydomain.com/app. That folder is actually a subdomain (added via dns and google webmaster tools): app.mydomain.com, and php application is hosted there. And it all works. Www redirect is working flawlessly on main domain, but in subdomain, it just doesn’t. They are using different .htaccess files.
Take a look at this .htaccess cestion (for subdomain):
ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} ^www\.app.\mydomain.\com$ [NC]
RewriteRule ^(.*)$ http://app.mydomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^ip\.ip\.ip\.ip
RewriteRule (.*) http://app.mydomain.com/$1 [R=301,L]
What’s the catch?
When you’re escaping periods, the backslash needs to be before the dot.
Change this line
to this: