How to redirect all pages from www to non www?


#1

I am editing my .htaccess file so that my site gets redirected from all www to non www pages .
I have tried using the follow two codes:
> RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC]
RewriteRule ^(.*)$ http:// mydomain .com/$1 [L,R=301]
** (i have inserted space here just to avoid link)

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

but none of them worked.
when i enter www to my home page it gets redirected to non www but when i do the same with other posts links it is displayed with www as well as non www.
i want to redirect all my pages also to non www version so what should i do?
when i enter;
www. mydomain .com it should redirect to mydomain .com
and also when i enter www. mydomain .com/xyz it should redirect to mydomain. com/xyz


Domain.com is working but www.domain.com is not working
#2

@pradeepkumar @iftiseo bro can you help??


#3

@hazard facing issue on Wordpress?


#4

Hi @hazard, can you kindly try this code and update me please? :slight_smile:

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

Replace example.com with your own domain name.


#5

@hazard

if you are facing issue on Wordpress

Just go to Settings > General > Update your Wordpress URL to non-www format

Next, Add this Below code on HTACCESS File

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

#6

Tried this code, but same problem is there.


#7

did that but this didnt solved…


#8

clear cache and check the site


#10

thanks @pradeepkumar @mskian issue solved, i just rebooted my droplet and cleared cache. :slight_smile: