【问题标题】:Forcing WWW with httpd.conf rather than .htaccess使用 httpd.conf 而不是 .htaccess 强制 WWW
【发布时间】:2011-04-01 04:18:36
【问题描述】:

我已经阅读了许多 Force WWW。使用 htaccess 的技巧。 (如下)

Rewritecond %{HTTP_HOST} !^www\.domain\.com
RewriteRule (.*) http://www.domina.com/$1 [R=301,L]

我想知道是否有一种方法可以强制在整个网站上使用 httpd.config 进行 WWW。

htaccess 很好用,但我有很多子目录,其中大多数都包含自己的 .htacess 文件,这会破坏该特定子目录中的强制 www。

所以我在想,有没有办法强制这个“www”。进入 httpd.config,无需编辑 .htaccess 即可跨整个站点?

谢谢。

【问题讨论】:

  • 为什么不加评论就投反对票? 5 年后,这对我很有帮助......

标签: apache .htaccess httpd.conf


【解决方案1】:

应该这样做:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

还要维护 HTTPS:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

【讨论】:

  • 这适用于我的站点根目录中的所有文件,但不适用于子目录。
【解决方案2】:

这对我有用

# direct all variation of FQDN to www.epoch.co.il
  RewriteEngine on

  #RewriteLogLevel 3
  #RewriteLog "/var/log/httpd/epoch/www/epoch-rewrite_log"

  RewriteCond %{HTTP_HOST}   !^www\.epoch\.co\.il [NC]
  RewriteCond %{HTTP_HOST}   !^$
  RewriteRule ^/(.*)         http://www.epoch.co.il/$1 [L,R]

【讨论】:

    猜你喜欢
    • 2014-06-16
    • 1970-01-01
    • 2013-05-31
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多