0

I am new to this htaccess . So please help me to find a solution .

Lets say i have a domain name = example.com

Now i want when any subdomain is entered it will open a particular file , For example

demo.example.com >> Will redirect >> demo.example.com/test.php

check.example.com >> Will redirect >> check.example.com/test.php

anything.example.com >> Will redirect >> anything.example.com/test.php

Now that test.php should be in website root folder , means the structure should be like this

For this i have already created a wild card subdomain as the same path as the main domain .

Can this be done via htaccess .

Thanks a lot in advance .

4

2 回答 2

2

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$
RewriteRule ^/?$ /sites/test.php [L]

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$
RewriteCond %{DOCUMENT_ROOT}/sites/$1 -f
RewriteRule ^(.*)$ /sites/$1 [L]
于 2013-09-06T21:36:10.960 回答
1

将此添加到所有文档根文件夹中的 htaccess 文件中:

RewriteEngine On
RewriteRule ^$ /test.php [L]

如果您想重定向浏览器以使“/test.php”显示在位置栏中,R请在方括号中包含一个标志: [L,R],或者[L,R=301]如果您希望永久缓存重定向,请使用 a 。

于 2013-09-06T21:21:31.657 回答