0

This question already has an answer here:

I have a wordpress website

mywebsite.net

on the wwww version www.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=$1&sitemap_n=$2 [L]
</IfModule>

marked as duplicate by Zistoloen, John Conde Jul 16 '15 at 13:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Ideally, you should only have 1 RewriteEngine On and 1 RewriteBase directive at the top of your .htaccess file. – MrWhite Jul 31 '15 at 20:08
  • thx @AndreaF for " Header set Access-Control-Allow-Origin "*" " – BG Bruno Oct 27 '18 at 17:26
1

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 ^(.*)$ http://example.com/$1 [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 ^(.*)$ http://%1/$1 [R=301,L]

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

  • Seems totally ignored :( – AndreaF Jul 16 '15 at 6:39
  • Is it not working? – Helping Hands Jul 16 '15 at 7:01
  • Exactly. I have tried but doesn't change. – AndreaF Jul 16 '15 at 12:28
  • For me same method is working.. – Helping Hands Jul 17 '15 at 2:45
  • @AndreaF The above directives need to go at the top your .htaccess file, before the WordPress rewrites. – MrWhite Jul 31 '15 at 19:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.