Mobile app version of vmapp.org
Login or Join
Holmes151

: How do I get rid of the "www" with mod_rewrite? I want to get rid of the "www" in front of my domain, and I'm trying the following, but it's not working: RewriteEngine On RewriteCond %{HTTP_POST}

@Holmes151

Posted in: #Apache #ModRewrite

I want to get rid of the "www" in front of my domain, and I'm trying the following, but it's not working:

RewriteEngine On
RewriteCond %{HTTP_POST} ^www.example.com [NC]
RewriteRule ^/(.*) example.com/ [L,R]


Basically, what I hope to accomplish is that someone going to example.com would be redirected to example.com.

Any ideas as to what I'm doing wrong?

I've even tried substituting the second line for this:

RewriteCond %{HTTP_POST} example.com [NC]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Holmes151

1 Comments

Sorted by latest first Latest Oldest Best

 

@Shelley277

Assuming your .htaccess is on the right place with the right permissions and
your Apache server is configured to use it and mod_rewrite is enabled:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^/?(.*)$ example.com/ [R=301,L]


Note the HTTP_HOST vs HTTP_POST in your example and that I use a 301 redirect.
This is better since some links may point to the www version and this will let
them count towards your SEO ranking. Search engines will eventually always
send people to the right place.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme