OptimusCrime
OptimusCrime

Reputation: 14863

Simple .htaccess to remove www does not work

I want to remove the www's from my url because it's messing with my cookies and people are having problem logging in.

My url for this site is www.example.no/ansatt/ and this htaccess does not work:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.no/ansatt$ [NC]
RewriteRule ^(.*)$ http://example.no/ansatt/$1 [R=301,L]

What am I doing wrong? I've tried every combination with slashes and without slashes. Mind that this is not ment for the whole site (example.no), just example.no/ansatt/

Upvotes: 0

Views: 62

Answers (1)

Jason McCreary
Jason McCreary

Reputation: 73011

HTTP_HOST does not include path information.

Just do the following:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.example\.no$ [NC]
RewriteRule ^(.*)$ http://example.no/$1 [R=301,L]

The rest will take care of itself. Also a reminder to escape literals (i.e. \.)

Upvotes: 2

Related Questions