Vuk
Vuk

Reputation: 35

How to redirect a root sub-folder to a sub-domain using htaccess rules

I am trying to redirect all the links of a subfolder to a new subdomain, so for example:

example.com/sso/ redirects to sso.example.com

example.com/sso/login redirects to sso.example.com/login

I have tried the following but it does not work:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^/sso/(.*) http://sso.example.com/$1 [R=301]
</IfModule>

Upvotes: 1

Views: 84

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133770

Could you please try following, written as per your shown samples. Please clear your browser cache after putting these rules in your htaccess file. Added few more options to your attempt, like to match sso ignore case mode. Added L flag to stop rule's processing after this, so that shouldn't conflict with other rules.

Also . in example.com should be escaped to make it treated as a literal character.

Options +FollowSymLinks
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(sso|SSO)/(.*)$ http://sso.example.com/$2 [R=301,NE,L]

Upvotes: 4

Related Questions