0

I am hosting sever sites by using virtual host of apache. Is there any way to redirect any sites hosted on our server to will redirect to non www

I want just one setting in the server so that every site hosted here and that will be hosted later will redirect to non www if there is a www in the request. I dnt like the .htaccess change for all the sites individually.

zahid9i
  • 596
  • 1
  • 8
  • 17

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\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

Just one rule like this will take care of removing www from all of your hosts.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I dont know'whether you understand the question or not. It seems you are suggesting answer for each of the domain hosted. I like to one solution for all the domains hosted and even will be hosted in future on my server. More clearly I dont like to use .htaccess Is there any solution in the setting of apache? thnx – zahid9i Sep 12 '13 at 01:25
  • 1
    I very well understand your question and provided answer which will take care of ALL the domains hosted, present and future. You can put this rule in your Apache config also instead of .htaccess. – anubhava Sep 12 '13 at 03:51