如何在服务器上的public_html /子域名使用通配符子域的文件夹中 [英] How to use wildcard subdomain in a folder on server public_html/subdomain

查看:535
本文介绍了如何在服务器上的public_html /子域名使用通配符子域的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的服务器上的文件夹中的public_html /子域通配符子域。我使用的PHP脚本如下 只是为了告诉你什么是我做的网页上:

 < PHP
 $子域=爆炸(,$ _ SERVER ['HTTP_HOST']'。');
 $子域=用strtolower(array_shift($子域));
 回声ucwords(str_replace函数(' - ','',$子域));
?>
 

现在的问题是,当example.domain.co.uk中键入它返回顶级的public_html / index.php文件,而不是的public_html /子域/ index.php文件

我收到这方面的工作,但我可能已经改变了的.htaccess通过误差

应该是什么的.htaccess文件,使这项工作?

我目前有:

 < IfModule mod_rewrite.c>
的RewriteCond%{} HTTPS!=上
的RewriteCond%{HTTP_HOST} ^ WWW \。(。+)$ [NC]
重写规则^ HTTP://%1%{REQUEST_URI} [R = 301,L]
< / IfModule>
从148.204允许。
从googlebot.com google.com允许
满足任何
 

新的code

  RewriteEngine叙述上
 # -首页-

IndexIgnore的.htaccess * /。?? *〜*#* / HEADER * * / README * * / _ VTI *

<限制GET POST>
为了否认,允许
所有否认
允许所有
< /限制>
<限制PUT DELETE>
为了否认,允许
所有否认
< /限制>
AuthName指令domain.co.uk
的AuthUserFile /home/****/public_html/_vti_pvt/service.pwd
目录AuthGroupFile /home/****/public_html/_vti_pvt/service.grp



RewriteEngine叙述上
< IfModule mod_rewrite.c>
的RewriteCond%{} HTTPS!=上
的RewriteCond%{HTTP_HOST} ^ WWW \。(。+)$ [NC]
重写规则^ HTTP://%1%{REQUEST_URI} [R = 301,L]
< / IfModule>
从148.204允许。
从googlebot.com google.com允许
满足任何

RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ WWW \。域\ .co.uk [NC]
重写规则(。*)http://domain.co.uk/$1 [R = 301,L]

RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .CO \ .UK $ [NC]
的RewriteCond%{HTTP_HOST} ^([^。] +)\。
的RewriteCond%{REQUEST_URI} ::%1!^ /([^ /] *)/(。*):: \ 1
重写规则^(。*)$ / 1%/ $ 1 [L]


ErrorDocument的404 /404.html
 

解决方案

htaccess的文件应该是这个样子:

 的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .CO \ .UK $ [NC]
的RewriteCond%{HTTP_HOST} ^([^。] +)\。
的RewriteCond%{REQUEST_URI} ::%1!^ /([^ /] *)/(。*):: \ 1
重写规则^(。*)$ / 1%/ $ 1 [L]
 

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

解决方案

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]

这篇关于如何在服务器上的public_html /子域名使用通配符子域的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆