0

I have a server that serves several domains from a single IP address using Apache's Virtual Host shenanigans. Three of the sites are required to redirect to www if it's omitted from the URL.

I have the following rule in the .htaccess file of each domain:

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

This works for two of the three, but the third completely fails to comply. I know that the .htaccess is being hit because the framework requires all hits to be routed through index.php... and that is happening correctly. So, it's not permissions, and the .htaccess is identical (more or less) on each domain. I even looked into caching (even though that doesn't make any sense... desperation gives way to insanity!)

Please help me if you have any clue what is going on.

As requested, here's the complete vhost config, and .htaccess file...

vhost configuration:

<VirtualHost *:80>
        ServerAdmin me@gmail.com
        DocumentRoot /var/www/example.com
        ServerName www.example.com
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/example.com>
                Options FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

.htaccess file:

# BEGIN example.com

<IfModule mod_rewrite.c>

RewriteEngine On

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

RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]

####################################################
# If requested URL-path plus ".php" exists as a file
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# Rewrite to append ".php" to extensionless URL-path
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
####################################################

# redirect to RoutingHandler
RewriteRule ^.*$ /index.php [NC,L]

</IfModule>

# END example.com

Bear in mind, there are two other domains set up in an identical manner... and they both work with zero issues.

4

1 回答 1

0

我知道这是一个老问题,但谷歌在寻找相同问题的答案时把我带到了这里。在搜索了 apache 的文档后,我发现: AllowOverride Directive

当此指令设置为 None 时,.htaccess 文件将被完全忽略。在这种情况下,服务器甚至不会尝试读取文件系统中的 .htaccess 文件。

因此,我在该部分中将“AllowOverride None”更改为“AllowOverride All”<Directory /var/www/example.com>并且它起作用了。

于 2014-02-14T06:13:27.980 回答