问题原文
原帖链接 · Maltiriel · CC BY-SA 4.0
I have an Apache webserver running a bunch of web apps. I have successfully redirected incoming http traffic to https for every individual app, but I'm having trouble routing ALL traffic coming to the root path (which has nothing on it) to a specific app. I've got it working for http but not https.
So essentially right now the following URLS redirect correctly:
http://example.com/app1 -> https://example.com/app1 http://example.com/app2 -> https://example.com/app2 etc. http://example.com -> https://example.com/app1
but I can't figure out how to make this work:
https://example.com -> https://example.com/app1
My Apache config file contains the following:
<VirtualHost xxx.xxx.xxx.xx:80>
ServerName example.com
RedirectMatch 301 ^/$ /app1/
Redirect permanent / https://example.com/
</VirtualHost>
I have tried adding RewriteCond/RewriteRule pairs such as
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^/$ https://example.com/app1 [R=301,L]
as well as loads of other things that I thought ought to work and they either seem to do nothing or break other parts of my configuration.
In case it matters my SSL cert is multidomain as I also have other domains pointing to apps on this server. All of those work perfectly fine with just the following (they have no additional redirect requirements though):
<VirtualHost xxx.xxx.xxx.xx:80>
ServerName example2.com
Redirect permanent / https://example2.com/
</VirtualHost>
So how can I make https redirect from root to a suburi without breaking anything else?
已采纳解答
原帖链接 · Gerard H. Pille · CC BY-SA 4.0
The same RewriteRule for http and https should do the trick, put them first if there are others. I prefer mod_rewrite over mod_alias.
<VirtualHost xxx.xxx.xxx.xx:80>
ServerName example.com
RewriteEngine On
RewriteRule ^/$ https://example.com/app1 [R=301,L]
</VirtualHost>
<VirtualHost xxx.xxx.xxx.xx:443>
ServerName example.com
RewriteEngine On
RewriteRule ^/$ https://example.com/app1 [R=301,L]
</VirtualHost>
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
