我想在下面实现以下目标。
重写(www.example.com, example.com
)至{https://example.com/folder
)而未在网址中显示/folder
,即(https://example.com
)
还希望其他请求(www.example.com/other-folders/..., example.com/other-folders/...
)重写为https
,即(https://example.com/other-folders/...
)
目前,我有以下内容:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*)$ /folder/$1
www.example.com
- 完美无缺
example.com
- 工作但返回此错误“检测到错误的访问权限,此服务器只能通过https://example.com/folder访问... 然后重定向但是显示/folder
www.example.com/other-folders
和example.com/other-folders
- 不起作用
答案 0 :(得分:0)
尝试:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/folder
RewriteRule (.*)$ /folder/$1