2

I'm trying to make .htaccess On this, I would like to state something in order to make visitor jump to the URL without www when it contains it as sub-domain.

How can I write? For example, when a user goes to the page http://www.test-sample.com/sign_up, I want it to redirect to http://test-sample.com/sign_up but only when it contains www in sub-domain. Because there is rare case such as http://forum.test-sample.com/1443

MKK
  • 2,713
  • 5
  • 31
  • 51
  • 1
    This looks to be a duplicate of: http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www – Bardicer Jul 16 '13 at 04:51
  • 1
    @Nick Thanks I've already tried that but it takes me to `http://test-sample.com/test-sample/public` :( – MKK Jul 16 '13 at 04:57

1 Answers1

2

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

This will only redirect www.example.com while leaving www.sub.example.com as it is.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks!! you are right!! It was because of cache! Thanks so much:) – MKK Jul 16 '13 at 05:03
  • MKK: The code provided in this answer should work fine. Make this as simple as you can, and just create an index.html file (or something to the same effect), to see whether the issue is with the server configuration, or with any applications you may be running. – Shane Jul 16 '13 at 05:03