2015-10-03 181 views
0

我有一个小问题,我不知道这是为什么。非www到www重定向htaccess

我想:

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

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

但是,没有更迭。

重定向从网站:http://domain.com to http://www.domain.com 但不能从http://domain.com/sample-page to http://www.domain.com/sample-page

为什么?

更新:我使用HHVM 3.6.6。这可能是原因?!并且.htaccess的地方位于httpd-app.conf(Bitnami HHVM)

+1

的[重定向非www到在.htaccess WWW]可能的复制(http://stackoverflow.com/questions/12050590/redirect-non-www-to-www-in-htaccess) –

+0

它可能是重复的,但是那一个是针对提问者遗漏了尾部斜线的情况 – Foon

+0

没有重定向非www到www的重复。此时此代码处于活动状态。 ** RewriteCond%{HTTP_HOST}!^ www \。 RewriteRule ^(。*)$ http://www.% {HTTP_HOST}/$ 1 [R = 301,L] ** – Alexcsandru

回答

0

Bitnami开发人员在这里。

如果您想默认应用此重定向,可以将其添加到“installdir/apache2/conf/bitnami/bitnami.conf”文件中的默认VirtualHost中。

<VirtualHost *:80> 
    ServerName app.example.com 
    ServerAlias www.app.example.com 
    RewriteEngine On 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
... 

<VirtualHost *:443> 
    ServerName app.example.com 
    ServerAlias www.app.example.com 
    RewriteEngine On 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
... 

请注意,您将需要重新启动Apache才能应用更改。

installdir/ctlscript.sh restart 

您可以通过此链接了解有关如何配置Apache的更多信息。

https://wiki.bitnami.com/Components/Apache

我希望它能帮助。

条田