Jitendra Vyas
Jitendra Vyas

Reputation: 152935

www to non-www redirection .htaccess code not woking on my site?

I want to redirect http://www.example.com to http://example.com via .htaccess. I've found and tried below listed codes but nothing works. can any body tell me the solution.

I get this error Socket Error 10049 on all codes when i type http://www.example.com

My hosting's Apache version is 2.0.63. My .htaccess file is in a public_html/

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


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


RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://example.com/ [R=301,L]

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

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

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

Upvotes: 0

Views: 1850

Answers (3)

bobince
bobince

Reputation: 536765

I get this error Socket Error 10049 on all codes

I don't think this is caused by www redirects. That's usually what you get when you try to ‘Listen’ on an IP address the server doesn't have. (Often when you copy an httpd.conf from one server to another.)

Incidentally if you've got access to the httpd.conf it's simpler and quicker to do a redirect for a single site using, well, ‘Redirect’.

<VirtualHost *:80>
    ServerName example.com
    ...real settings...
</VirtualHost>
<VirtualHost *:80>
    ServerName www.example.com
    Redirect permanent / http://example.com/
</VirtualHost>

Upvotes: 3

zalew
zalew

Reputation: 10311

http://no-www.org/

try

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

Upvotes: 0

Related Questions