简体   繁体   中英

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>

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]

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