我在一个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.
<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>
<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 certs),但是没有重定向规则。
如何为这两个应用程序配置重写规则以使其正常工作?
提前致谢, 亲切的问候!
答案 0 :(得分:0)
您似乎正在尝试将流量重定向到HTTPS;我假设这是正确的吗?
如果是,请尝试:
删除它:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
并将其替换为:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}