如何重写子域的规则 [英] How to rewrite rules for sub-domains
问题描述
我最近注册了一个域名 kbcsurveyors.com.然后,我创建了两个子域,它们在根文件夹中创建了两个新文件夹.
I recently registered a domain name kbcsurveyors.com. Then, I created two sub-domains, which created two new folders in the root folder.
我的动机是,如果我输入 kbcsurveyors.com/preinspection,它应该指向 preinspection.kbcsurveyors.com强>.其他子域也一样.
My motive is that if I type kbcsurveyors.com/preinspection, it should point to preinspection.kbcsurveyors.com. Same for other sub domains.
在我放置在 mydomainname.com 根目录中的 .htaccess 中,我写了以下几行:
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.
如何编写 .htaccess 文件来实现我想要的?
How do I write the .htaccess file to achieve what I want?
问候
推荐答案
删除或注释掉您现有的规则.
Remove or comment out your existing rule.
使用此规则创建一个新文件 preinspection/.htaccess
:
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]
这篇关于如何重写子域的规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!