Mobile app version of vmapp.org
Login or Join
Cooney921

: Redirect www to non-www using Apache htaccess does not work I have this in my .htaccess (modified from the default Drupal .htaccess): RewriteCond %{HTTP_HOST} ^www.website.com.com$ [NC] RewriteRule

@Cooney921

Posted in: #Apache2 #Htaccess #ModRewrite #UrlRewriting

I have this in my .htaccess (modified from the default Drupal .htaccess):

RewriteCond %{HTTP_HOST} ^www.website.com.com$ [NC]
RewriteRule ^(.*)$ website.com/ [L,R=301]


In theory this will redirect something like www.website.com/asdf to website.com/asdf. However, it doesn't redirect, it allows requests to go through like there was no redirect intended.

(I'm on OS X if it matters, but I've also tried it on a Network Solutions Linux server with the same result.)

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Cooney921

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

You need to enable the rewrite engine in your .htaccess file if you have not done already...

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ example.com/ [L,R=301]


Note that I've removed the extra .com on the RewriteCond line that you have in your question - I'm assuming this was a typo?

Also, FollowSymLinks must also be enabled, if not already (should appear before the above)

Options +FollowSymLinks


If it's still not doing anything then it's possible the .htaccess file (or these directives) are not being processed at all. (You can test this by typing some nonsense and see if it breaks!) In which case, look for the AllowOverride directive in your server config / virtual host settings and set this to AllowOverride All (it might be set to None for instance) - or query this with your host.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme