我正在尝试使用htaccess文件中的以下规则将example.com/x/y/..
重定向到https://sub.example.com/x/y/..
:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ https://sub.example.com/$1 [L,R=301]
但重定向不会将原始URL的子路径添加到新路径。因此,我只是重定向到https://sub.example.com/x/y/..
https://sub.example.com
。
有什么建议吗?
答案 0 :(得分:0)
在您描述的当前场景中,Apache无法传递URI的剩余部分。您需要在RewriteRule的行中使用%{HTTP_HOST}%{REQUEST_URI}
。请参阅此示例:Force SSL/https using .htaccess and mod_rewrite