我有一臺服務器,它使用Apache的虛擬主機shenanig從一個IP地址提供多個域。如果從網址中省略了三個網站,則需要重定向到www
。mod_rewrite:一個服務器上的多個域,mod_rewrite拒絕在一個服務器上工作
我在.htaccess
文件中的每個域的以下規則:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
這適用於兩三個,但是第三個完全沒有遵守。我知道.htaccess
正在被擊中,因爲該框架要求通過index.php
路由所有命中......並且正確地發生。所以,這不是權限,並且每個域上的.htaccess
都是相同的(或多或少)。我甚至考慮過緩存(儘管這沒有任何意義......絕望讓位於瘋狂!)
請幫助我,如果你有任何線索是怎麼回事。
按照要求,這裏的完整vhost
配置,並.htaccess
文件...
vhost
配置:
<VirtualHost *:80>
ServerAdmin [email protected]
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
文件:
# 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
請記住,有兩個其他領域以相同的方式建立......並且他們都以零問題工作。
它看起來很好......除了'www'問題。我非常努力地確保它能夠提供正確的代碼。我知道搞亂vhost配置是多麼容易。 – 2013-04-22 06:59:01
我甚至嘗試了一個明確提到域名的正則表達式版本......'^ domain \ .com $'...沒有運氣。它只是'domain.com',沒什麼特別的。我完全被難住了。 – 2013-04-22 07:10:26
也許如果你用有關域的完整信息更新你的問題,包括相關的vhost配置和其他相關的.htaccess文件中的代碼,有人可能能夠找出問題所在。 – 2013-04-22 07:24:56