How to rewrite rules for sub-domains

匆匆过客 提交于 2019-12-25 06:30:08

问题


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

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.

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

Regards


回答1:


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]


来源:https://stackoverflow.com/questions/43195242/how-to-rewrite-rules-for-sub-domains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!