0

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]
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852
  • The problem is that you're using Windows. Seriously though, are you sure that .htaccess is causing the problem? And are you ACTUALLY using www.example.com? If so, choose another hostname. – Artelius Apr 17 '09 at 06:59

3 Answers3

3

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>
bobince
  • 528,062
  • 107
  • 651
  • 834
  • ++ and you can also do RedirectMatch permanent ^/(.*) http://example.com/$1 to generally improve the user experience and also not break any incoming links. – cherouvim Apr 19 '09 at 05:48
  • The ‘Redirect’ version already does that: trailing URL parts are automatically appended to the target URL. – bobince Apr 19 '09 at 14:55
0

Hope this helps.

http://basilvarghese.co.cc/using-htaccess-for-redirection.html

0

http://no-www.org/

try

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