How to rewrite rules for sub-domains

2019-09-07 08:51发布

I recently registered a domain name kbcsurveyors.com. Then, I created two sub-domains, which created two new folders in the root folder.

enter image description here

My motive is that if I type kbcsurveyors.com/preinspection, it should point to preinspection.kbcsurveyors.com. Same for other sub domains.

In my .htaccess, which I placed inside root of mydomainname.com, I have written following lines:

RewriteEngine  On                                     
RewriteBase /
RewriteRule ^preinspection/(.*)$          https://kbcsurveyors.com/$1 [L,NC,QSA]    # Handle requests for "Preinspection"

But this file structure does not work.

enter image description here

How do I write the .htaccess file to achieve what I want?

Regards

1条回答
放荡不羁爱自由
2楼-- · 2019-09-07 09:35

Remove or comment out your existing rule.

Create a new file preinspection/.htaccess with this rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^preinspection\.kbcsurveyors\.com$ [NC]
RewriteEngine .* http://preinspection.kbcsurveyors.com/$0 [L,NE,R=301]
查看更多
登录 后发表回答