Mod rewrite Apache2未拾取重写规则
我有一个域正在使用两个独立的virtualhost文件:一个用于:80,另一个用于:443 :80设置非常简单,唯一的任务是重定向到:443:Mod rewrite Apache2未拾取重写规则,mod-rewrite,apache2,Mod Rewrite,Apache2,我有一个域正在使用两个独立的virtualhost文件:一个用于:80,另一个用于:443 :80设置非常简单,唯一的任务是重定向到:443: <VirtualHost *:80> # This is the first host so it's the default. # So although I've specified a ServerName and ServerAlias anything else not specified elsewhere wil
<VirtualHost *:80>
# This is the first host so it's the default.
# So although I've specified a ServerName and ServerAlias anything else not specified elsewhere will also end up here.
ServerName www.domain.com
ServerAlias domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Redirect everything to https:
RewriteEngine on
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301,L]
</VirtualHost>
哪个应该重写
->但现在它只是指向我的404文件
这可能是显而易见的,但我没有看到我的错误。注意:这并不能解决此处所述的问题,但它确实解决了根本问题 由于这是一个生产环境(多么尴尬),我的Web服务器一开始非常脆弱,但很快就被淹没了。我的公司大大增加了我的预算(我们预计会有很多流量,但我们希望它会慢慢增加,但事实并非如此),因此我能够设置多台服务器,并在它们前面放置2台HAProxy负载平衡器。我使用HAProxy配置解决我的问题,使用:
frontend http
bind MY_IP:80
redirect prefix http://www.domain.com code 301 if { hdr(host) -i domain.com }
redirect scheme https code 301 if !{ ssl_fc }
frontend https
bind MY_IP:443 ssl crt /etc/haproxy/certs/domain.com.pem
redirect prefix https://www.domain.com code 301 if { hdr(host) -i domain.com }
reqadd X-Forwarded-Proto:\ https
default_backend app_pool
backend app_pool
balance roundrobin
redirect scheme https if !{ ssl_fc }
server app-1 MY_IP:80 check
server app-2 MY_IP:80 check
server app-3 MY_IP:80 check
server app-4 MY_IP:80 check
它将始终重定向到www.domain.com版本,并强制使用HTTPS。在我看来,在HAProxy中设置它比使用VirtualHost容易得多
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.domain.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301]
RewriteRule ^subpage/(.+)/?$ subpage.html?$1 [NC]
frontend http
bind MY_IP:80
redirect prefix http://www.domain.com code 301 if { hdr(host) -i domain.com }
redirect scheme https code 301 if !{ ssl_fc }
frontend https
bind MY_IP:443 ssl crt /etc/haproxy/certs/domain.com.pem
redirect prefix https://www.domain.com code 301 if { hdr(host) -i domain.com }
reqadd X-Forwarded-Proto:\ https
default_backend app_pool
backend app_pool
balance roundrobin
redirect scheme https if !{ ssl_fc }
server app-1 MY_IP:80 check
server app-2 MY_IP:80 check
server app-3 MY_IP:80 check
server app-4 MY_IP:80 check