Frage

I want to remove "www" from my domain at apache2. I tryed out lots of examples whiches do it with an .htaccess file but none of them works. So here's my .htacces which is owned by user root with chmod 644:

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

This is not removing the www and if I type http://your-site.com in my browser (Firefox) it redirects me to www.your-domain.com stil. EDIT: It was browser's fail, but prev. problem exists.

My apache2 is setted up for this main domain without www. already and that was my all .htaccess.

War es hilfreich?

Lösung

The easy solution I use from No WWW, Better SEO is to start each .htaccess with the following:

RewriteEngine On
RewriteBase /

# FROM www. --TO-- NO www.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

This is just a cut and paste no brainer. It is the first thing on each .htaccess I have on hundreds of sites and domains.

Andere Tipps

Find the error in apache log:

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

So the problem were apache2 was misconfigured...

Solved with command: sudo a2enmod rewrite from this thread: https://stackoverflow.com/a/11649987/1725341

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top