views:

415

answers:

4

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]
A: 

http://no-www.org/

try

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
zalew
it's not works i've tried this too http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www
metal-gear-solid
+2  A: 

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
++ 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
The ‘Redirect’ version already does that: trailing URL parts are automatically appended to the target URL.
bobince
A: 

I have created .htaccess file under my document root folder in linux, but it is not working. So what are the configurations I should have in hand before I upload the above .htaccess file?

I am using RedHat Linux ES 4.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain
RewriteRule (.*) http://www.mydomain/$1 [R=301,L]
You probably should post this as a new question, not as an answer to an old question. In the upper right there is a "Ask Question" button that allows you to ask a new question.
sth
A: 

Hope this helps.

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