【发布时间】:2014-10-16 13:44:38
【问题描述】:
我在一个 apache 上配置了两个应用程序(例如 example.com 和 test.net)。这些应用程序的重写规则是相同的(所以在域 example.com 的配置文件中我有这个规则,并且在 test.net 域的 conf 文件中的规则相同)
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
它几乎可以正常工作,除了一种情况 - 当我在 webwrowser https://www.test.net 中请求时。
在这种情况下,apache 重定向到 https://www.test.net but displays content of https://www.example.com (not content of https://www.test.net as it should). Request www.test.net works ok. And https://www.example.com also works ok.
这是 test.net 的整个虚拟主机配置(example.com 的配置是类比的):
<VirtualHost *:80>
ServerName test.net
ServerAlias www.test.net
DocumentRoot /var/www/test/web/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/test/web/>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/test_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/test_access.log combined
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
</VirtualHost>
以及 example.com 的虚拟主机文件
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example/>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
我当然也有 ssl 设置的配置文件(例如 ssl 证书),但没有重定向规则。
如何为这两个应用配置重写规则,使其正常工作?
提前致谢, 亲切的问候!
【问题讨论】:
标签: apache mod-rewrite rewrite