我的应用程序运行于https://example.com/app. 我想要重定向https://example.com/到https://example.com/app。我的站点配置文件中的重定向规则如下。如何根据我的需要进行修改?
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://%{HTTP:Host}%{REQUEST_URI} [L,R=PERMANENT]
答案1
如果你想重定向你的客户端(HTTP 301),尝试这个:
# Redirect entire site ("/") without Query-Strings
Redirect 301 / http://www.example.com/app/
# Redirect all requests to "/" with Query-Strings
RewriteRule ^(.*) http://www.example.com%{REQUEST_URI} [R=301,NC]
如果你想改写请求(内部):
RewriteEngine on
RewriteBase /
# Condition: Rewrite all URLS without app in them ...
RewriteCond %{REQUEST_URI} !^/app/
# Condition:Rewrite all URLS from Domain ...
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Action: Rewrite to insert /app/<request>
RewriteRule ^(.*)$ /app/$1 [L]