cakephp中webroot文件夹的URL重定向

时间:2018-06-07 09:18:45

标签: php apache .htaccess mod-rewrite cakephp

我正在尝试重定向webroot文件夹的URL,即

https://test.example.com/ to https://www.example.com/test

其中test => webroot文件夹。

我在webroot / .htaccess

中尝试过重定向
<IfModule mod_rewrite.c>

RewriteEngine on
Redirect 301 /http://test.example.com http://example.com/test
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

也试过以下一个:

<IfModule mod_rewrite.c>
Options +FollowSymLinks 
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^https://test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/test/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

请帮我解决这个问题..

2 个答案:

答案 0 :(得分:2)

尝试以下,

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.+)\.example.com
RewriteRule ^ https://www.example.com/%1%{REQUEST_URI} [L,R=301]

答案 1 :(得分:0)

这将有效:

<IfModule mod_rewrite.c>

RewriteEngine on
Redirect 301 / http://example.com/test/
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>
相关问题