Forcing WWW with httpd.conf rather than .htaccess

浪子不回头ぞ 提交于 2019-12-24 20:09:05

问题


I've read up on many Force WWW. tricks using htaccess. (As Below)

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

I'm wondering if there is a method to force WWW using httpd.config across the entire site.

The htaccess works a treat, but I have many subdirectories, most of them include there own .htacess files, which breaks the force www in that particular subdirectory.

So I was thinking, is there a way to force this "www." into httpd.config, across the entire site without editing .htaccess?

Thanks.


回答1:


This should do it:

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

And to maintain HTTPS too:

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



回答2:


This works for me

# 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]


来源:https://stackoverflow.com/questions/5509113/forcing-www-with-httpd-conf-rather-than-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!