强制WWW与httpd.conf文件,而不是的.htaccess是的、而不、文件、httpd

2023-09-02 01:15:54 作者:无处安放的痛

我已经在许多部队WWW读了起来。使用htaccess的把戏。 (如下图)

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]

我不知道是否有一种方法在整个网站中使用httpd.config强制WWW。

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

htaccess的作品一种享受,但我有很多子目录,其中大部分包含有自己的.htacess文件,它打破了WWW力在特定的子目录。

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.

所以,我在想,有没有办法迫使这个WWW。进入httpd.config,跨不进行编辑的.htaccess整个网站?

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

感谢。

推荐答案

这应该做到这一点:

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]