3

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

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

In theory this will redirect something like http://www.website.com/asdf to http://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.)

3

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 ^(.*)$ http://example.com/$1 [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.

  • They are both in the .htaccess a few lines earlier – Josh The Geek Nov 17 '13 at 1:21
  • If you are not on a live server then you can make an obvious syntax error to see if your site breaks! If not then the file (or these directives) are not being processed at all. In which case, look for the AllowOverride directive in your server config / virtual host and set this to AllowOverride All - or query this with your host. (Although I'm a bit puzzled why this wouldn't be enabled at Network Solutions, so maybe this is not the problem?!) – MrWhite Nov 17 '13 at 1:44
  • I have tried just typing random stuff to ensure it's being parsed, and it is. Also, I know it is read because my Drupal URL's don't include the index.php?q=, which is less than five lines later in the .htaccess. The duplicated .com was just a typo when changing the URL. I've tried a few different variations of this from around the web, and none of them seem to work. I'm really at a loss here as to what the issue is... – Josh The Geek Nov 17 '13 at 13:40
  • In that case, there is something else in your .htaccess file (or your code) that is preventing this from redirecting. The code you have posted is OK in itself. This code is presumably at the top of your .htaccess file? And you have a single .htaccess file in the root of your site? – MrWhite Nov 17 '13 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.