.htaccess rewrite www to non-www and remove .html

Posted by lester8891 on Pro Webmasters See other posts from Pro Webmasters or by lester8891
Published on 2011-11-09T20:57:40Z Indexed on 2011/11/14 18:13 UTC
Read the original article Hit count: 366

I need rewrite rules to redirect the following:

http://www. to http://

/file.html to /file

I've tried using a combination of these but each time it results in a redirect loop on one of the situations

RewriteBase /
RewriteRule ^(.*)\.html$ $1 [NC]

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

I figure it's probably something to do with the flags but I don't know how to fix it. Just to be clear it needs to do all these situations:

http://www.domain.co.uk to http://domain.co.uk
http://www.domain.co.uk/file.html to http://domain.co.uk/file
http://domain.co.uk to http://domain.co.uk
http://domain.co.uk/file.html to http://domain.co.uk/file

Thanks!

© Pro Webmasters or respective owner

Related posts about htaccess

Related posts about redirects