Reputation: 211
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..
Upvotes: 1
Views: 320
Reputation: 7476
Try with below,
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.+)\.example.com
RewriteRule ^ https://www.example.com/%1%{REQUEST_URI} [L,R=301]
Upvotes: 2
Reputation: 2852
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>
Upvotes: 0