Mobile app version of vmapp.org
Login or Join
Angie530

: How to use htaccess to redirect from www to non-www version of the site I have a wordpress website mywebsite.net on the wwww version www.mywebsite.net wordpress doesn't load so want that

@Angie530

Posted in: #Htaccess #Redirects

I have a wordpress website

mywebsite.net


on the wwww version mywebsite.net wordpress doesn't load

so want that if the user open the www version of my website is redirect to the non-wwww version

here my .htaccess

# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteBase /

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# Enable cross-domain CORS

<FilesMatch ".(ttf|otf|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

# WordPress SEO - XML Sitemap Rewrite Fix
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=&sitemap_n= [L]
</IfModule>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Angie530

1 Comments

Sorted by latest first Latest Oldest Best

 

@Angie530

You can redirect your site from www to non-www version by 2 diff. ways :

First Method is

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


You can use above code in you Htaccess. But it will be something like hardcoded code as you have to specify domain name. It will work fine.

Second Method is :

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


Put above code in your Htaccess file.It is dynamic code. Here no need to specify domain name.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme