Syntax for 301 redirect of www to non-www using httpd.conf

后端 未结 1 1893
后悔当初
后悔当初 2020-12-11 16:37

How do I setup a rule (on httpd.conf) to redirect all the traffic from www.domain.com to domain.com? Will the following work?

<         


        
相关标签:
1条回答
  • 2020-12-11 17:26

    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>
    

    The Redirect 301 is good to use but does not have the same flexibility as a rewrite rule.

    0 讨论(0)
提交回复
热议问题