: 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
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>
More posts by @Angie530
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.