Redirect www.mydomain.com to mydomain.com

scrame

New Member
Messages
6
Reaction score
0
Points
0
So, I've been looking all over for a way to do this, but I want users to only use the non-www version of my website. Most of what I've seen says to use the htaccess file to set sort of a global redirect to remove the www.

Now, I've been messing with the htaccess and everything I do results in a redirect error (it looks like it's a neverending loop issue).

I guess the main question I have is whether or not htaccess is the way to do this. If so, what code should I be using? And if not, what else should I be looking into?

Thanks in advance for any help, I've been playing with this all day and having absolutely no luck... seems like a pretty simple problem, but I can't find an answer... Thanks!
 

Zubair

Community Leader
Community Support
Messages
8,766
Reaction score
305
Points
83
Add this in your .htaccess file
Code:
Options +FollowSymlinks
RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)   http://www.%{HTTP_HOST}/$1  [QSA,L,R=301]
 
Last edited:

scrame

New Member
Messages
6
Reaction score
0
Points
0
Thanks for responding, I hadn't been able to get anything else to work, but this one is getting somewhere.

One question, should I be replacing 'yourdomain.com' with my actual domain? The only reason that I ask is that when I leave it as yourdomain.com it works but when I change it to xyz.com, it doesn't. Does that make any sense?

The other question is that I would prefer that people who do enter the www.xyz.com be taken to zyz.com. Is there an easy way to do this as well?
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
This should work (Boss turned it around and added some useless code to it) :
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=permanent, L]

And yes, you can replace "yoursite.com" with your actual domain.

Edit: about your www.xyz.com to zyz.com, are you sure that's not a typo? Either way, if you replace the "www.yoursite.com" with "www.xyz.com" and the second "yoursite.com" to "zyz.com" it should work.
 
Last edited:
Top