Reputation: 2037
I want to redirect
it.example.com/it
to https://example.com/it
in .htaccess
How would I do it? I used this
RewriteCond %{HTTP_HOST} ^it.example.com/it
RewriteRule ^(.*)$ https://example.com/it/$1 [R=301,L]
but it didn't work.
I use another .htaccess file in it directory. its content is
RewriteBase /it/
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]]
Upvotes: 2
Views: 215
Reputation: 133428
You are trying to match URI in host variable, you need to remove your uri part from it. Could you please try following, written and tested with shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^it\.(example\.com)$ [NC]
RewriteRule ^(.*)/?$ http://%1/$1 [R=301,NE,L]
Upvotes: 0
Reputation: 784898
HTTP_HOST
only matches host/domain name. It doesn't match URI.
You may use:
RewriteCond %{HTTP_HOST} ^it\.(example\.com)$ [NC]
RewriteRule ^it(?:/|$) https://%1%{REQUEST_URI} [R=301,L,NE.NC]
Upvotes: 1