简体   繁体   中英

URL redirection of webroot folder in cakephp

I am trying to redirect the URL of webroot folder ie,

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

where test => webroot folder.

I have tried redirection in 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>

also tried the following one :

<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>

Please help me to solve this..

Try with below,

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

This will work:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM