简体   繁体   English

如何使用 htaccess 规则将根子文件夹重定向到子域

[英]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/重定向到sso.example.com

example.com/sso/login redirects to sso.example.com/login example.com/sso/login重定向到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.将这些规则放入您的 htaccess 文件后,请清除浏览器缓存。 Added few more options to your attempt, like to match sso ignore case mode.为您的尝试添加了更多选项,例如匹配 sso 忽略大小写模式。 Added L flag to stop rule's processing after this, so that shouldn't conflict with other rules.添加L标志以在此之后停止规则的处理,因此不应与其他规则冲突。

Also .. in example.com should be escaped to make it treated as a literal character.example.com应该转义以使其被视为文字字符。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM