문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top