Question

Say, My Website is : www.example.com

I have one page : www.example.com/contactus

If I remove "www." from above url, means : example.com/contactus

It redirects me to the homepage. Why ??

Checkout Following Image of .htaccess :

enter image description here

What is the Solution for it ??

What changes i have to make in .htaccess

Was it helpful?

Solution

Your htaccess is kinda hard to read but nothing seems to redirect the user, I think it's your Magento baseurl that does that.

Have you tried adding the following code to the htaccess to redirect to www. on that level?

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

OTHER TIPS

There is a setting in system->configuration->Web->Url Options->Auto-redirect to Base URL. Set that to 'No'.

Personal opinion: This setting is a big source of trouble specially when running multiple websites from the same magento instance. I always disable it.

this is the only question I found with Google according this issue.

Here is my solution for nginx as reverse proxy to apache. I'm running magento 1.8.0.0 as multisite. I also have multi domain SSL installed. I've disabled it and tried to make redirect with .htaccess config (as Sander Mangel suggested), but I ended up with redirect loop on https:// pages.

If there is Nginx set up as reverse proxy to apache then try to edit nginx vhost files like this:

server {
listen 80;
listen 443 ssl;
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
ssl_certificate     /path/to/your/ssl/domain.crt;
ssl_certificate_key /path/to/your/ssl/domain.key;
ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers         HIGH:!aNULL:!MD5;
ssl_session_cache    shared:SSL:10m;
ssl_session_timeout  10m;
}
server {
listen 80;
listen 443 ssl;
server_name domain.com;
ssl_certificate     /path/to/your/ssl/domain.crt;
ssl_certificate_key /path/to/your/ssl/domain.key;
ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers         HIGH:!aNULL:!MD5;
ssl_session_cache    shared:SSL:10m;
ssl_session_timeout  10m;
.... // the rest of config goes here
}

Then restart nginx (like /etc/init.d/nginx restart)

That it. 301 Redirect should work on every page redirecting www to non-www

Thanks,

Sharif

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top