语法的www 301重定向到使用非www的httpd.conf [英] Syntax for 301 redirect of www to non-www using httpd.conf

查看:227
本文介绍了语法的www 301重定向到使用非www的httpd.conf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置一个规则(在httpd.conf中)重定向从 www.domain.com 所有流量 domain.com ?请问下面的工作?

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?

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

其中,的我应该放在的httpd.conf 这个标签吗?是否为了有关系吗?

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

推荐答案

这是你可以使用的一个例子/ DO:

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>

在重定向301是很好用,但不具有同样的灵活性作为一个重写规则。

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

这篇关于语法的www 301重定向到使用非www的httpd.conf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆