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

帅比萌擦擦* 提交于 2019-12-12 01:26:33

问题


I have a wildcard subdomain in a folder public_html/subdomain on my server. I am using php script as follows Just to show you what I am doing on the page:

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

The problem is when example.domain.co.uk is typed in it returns the top level public_html/index.php file and not the public_html/subdomain/index.php

I had this working before but I may have changed the .htaccess by error

What should be in the .htaccess file to make this work?

I currently have:

<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

New Code

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

回答1:


The htaccess file should look something like this:

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


来源:https://stackoverflow.com/questions/19367349/how-to-use-wildcard-subdomain-in-a-folder-on-server-public-html-subdomain

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