Darwin
Darwin

Reputation: 2037

Redirect subdomain and folder by htaccess

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.

enter image description here

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

Answers (2)

RavinderSingh13
RavinderSingh13

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

anubhava
anubhava

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

Related Questions