-4

I want to make a rule in my .htaccess file, to redirect my www.example.com and www.example.com/index.html to example.com

Thanks

  • Possible duplicate of [Generic htaccess redirect www to non-www](http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) – Abhishek Gurjar Aug 20 '16 at 17:30
  • RewriteEngine On RewriteRule ^index\.html$ / [R=301,L] RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L] RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] – Diego Velazquez Aug 21 '16 at 02:28

3 Answers3

1

You can combine both requirement in a single rule like this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{THE_REQUEST} /index\.html[?\s] [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*?)(?:index\.html)?$ http://%1/$1 [L,R=301,NE,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Create a .htaccess file. And add this:

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.YOURDOMAIN\.com [NC]
RewriteRule ^(.*)$ http://YOURDOMAIN.com/$1 [L,R=301]
Mert
  • 151
  • 2
  • 9
0

thiis should work seamlessly

RewriteCond %{HTTP_HOST} ^www\.sitename\.com [NC]
RewriteRule ^(.*)$ https://sitename.com/$1 [L,R=301,NC]
Kofi Sammie
  • 3,237
  • 1
  • 17
  • 17