1

I pretty much know nothing about about .htaccess editing or regex expressions. What I have done to try to make my site re-direct from www versions to non-www versions is I followed the answers posted here:

redirect www to non-www

However, what I get is that if I enter www.example.com, I get:

example.com/example.com/ and a 404 error on my site

This is my .htaccess file:

#Adjust default time zone 
SetEnv TZ America/Toronto

#Begin redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]

# Google Analytics Integration - Added by cPanel.
<IfModule mod_substitute.c>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<script src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i"
</IfModule>
# END Google Analytics Integration

Can someone enlighten me on what I am doing wrong?

Community
  • 1
  • 1
q.Then
  • 2,743
  • 1
  • 21
  • 31
  • How are you getting `example.com/example.com/` in redirected URL? Did you try clearing your browser cache? – anubhava Oct 05 '15 at 07:17
  • There must be something else in your configuration files or in .htaccess. Or maybe the site is in a subdirectory and there is some problem with the directory prefix. – Olaf Dietsche Oct 06 '15 at 11:14

1 Answers1

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

That is, check if the HTTP_HOST contains www and if so, redirect to non-www with the request_uri appended.

Jan
  • 42,290
  • 8
  • 54
  • 79