Syntax for 301 redirecting www to non-www using httpd.conf

How to configure a rule (on httpd.conf) to redirect all traffic from www.domain.com to domain.com ? Will there be a next job?

 <VirtualHost www.domain.com> Redirect 301 / http://domain.com/ </VirtualHost> 

Where should I put this tag in httpd.conf ? Does order matter?

+8
apache mod-rewrite
source share
1 answer

This is an example of what you can use / do:

 <VirtualHost *:80> DocumentRoot "/var/www/domain.com" ServerName domain.com ServerAlias domain.com www.domain.com <Directory "/path/to/public_html"> allow from all Options +Indexes </Directory> Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} ^www.domain.com [NC] RewriteRule (.*) http://domain.com%{REQUEST_URI} [R=301,L] </VirtualHost> 

Redirect 301 is useful to use, but does not have the same flexibility as a rewriter.

+14
source

All Articles