Reputation: 152935
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
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
Reputation:
Hope this helps.
http://basilvarghese.co.cc/using-htaccess-for-redirection.html
Upvotes: 0
Reputation: 10311
try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Upvotes: 0