如何在服务器public_html/子域上的文件夹中使用通配符子域


How to use wildcard subdomain in a folder on server public_html/subdomain

我在服务器上的文件夹public_html/子域中有一个通配符子域。我正在使用 php 脚本如下只是为了向您展示我在页面上所做的事情:

 <?php
 $subdomain = explode('.', $_SERVER['HTTP_HOST']);
 $subdomain = strtolower(array_shift($subdomain));
 echo ucwords(str_replace('-', ' ', $subdomain));
?>

问题是当输入 example.domain.co.uk 时,它会返回顶级public_html/索引.php文件,而不是public_html/子域/索引.php

我以前有过这个工作,但我可能错误地更改了 .htaccess

.htaccess文件中应该有什么才能使这项工作?

我目前有:

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Allow from 148.204.
Allow from googlebot.com google.com
satisfy any

新代码

RewriteEngine On
 # -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName domain.co.uk
AuthUserFile /home/****/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/****/public_html/_vti_pvt/service.grp

RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Allow from 148.204.
Allow from googlebot.com google.com
satisfy any
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www'.domain'.co.uk [NC]
RewriteRule (.*) http://domain.co.uk/$1 [R=301,L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www'.)?domain'.co'.uk$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)'.
RewriteCond %{REQUEST_URI}::%1 !^/([^/]*)/?(.*)::'1
RewriteRule ^(.*)$ /%1/$1 [L]

ErrorDocument 404 /404.html

htaccess 文件应如下所示:

RewriteCond %{HTTP_HOST} !^(www'.)?domain'.co'.uk$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)'.
RewriteCond %{REQUEST_URI}::%1 !^/([^/]*)/?(.*)::'1
RewriteRule ^(.*)$ /%1/$1 [L]