hostgator:通配符子域到URL的映射 [英] hostgator: wildcard subdomain mapping to URL
问题描述
过去3个小时,我一直在hostgator共享托管服务器上解决此问题.这是最简单的问题.
I have been struggling with this problem on hostgator shared hosting server for the past 3 hours. This is the problem in the simplest.
这是我想发生的映射: subdomain.domain.com-> www.domain.com/test.php?user=subdomain
This is the mapping i want to happen: subdomain.domain.com --> www.domain.com/test.php?user=subdomain
但是由于某种原因,每当我输入"subdomain.domain.com"时,重定向都不会发生,即使URL在我的浏览器中也不会更改.而且我在加载的页面上看到了test.php文件(因为我在服务器上仅有的文件是.htaccess和test.php).
but for some reason whenever i enter "subdomain.domain.com" the redirection doesn't happen and even the URL doesn't change in my browser. And I see test.php file listed on loaded page (because The only files i have on server are .htaccess and test.php).
这是.htacess代码
This is the .htacess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
<IfModule mod_proxy.c>
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).domain.com(.*)$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/test.php?user=$1$2 [P,L]
</IfModule>
<IfModule !mod_proxy.c>
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).domain.com(.*)$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/test.php?user=$1$2 [R=301,L]
</IfModule>
</IfModule>
这是test.php代码
and this is the test.php code
<?php echo $_GET['user']; ?>
有人知道这里的问题吗?支持对我没有帮助.我认为服务器配置有问题.
does anyone know what the issue here is? the support was not helpful to me. i think there is something wrong with the server configuration.
推荐答案
RewriteCond
向后引用使用百分比,而不是美元符号! %1而不是$ 1.
RewriteCond
backreferences use a percent, not dollar sign! %1 not $1.
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).domain.com(.*)$ [NC]
^ %1 ^ %2
RewriteRule ^(.*)$ http://www.domain.com/test.php?user=$1$2 [R=301,L]
^$1 ^^^^ oops
$1
表示从左侧的正则表达式中提取内容; %1表示将其从RewriteCond
中拉出.假设重写者不会因为$2
是一个悬而未决的反向引用这一事实而感到沮丧,那么您可能会将整个比赛作为用户部分坚持下去.
$1
means pull something from the regex on the left; %1 means pull it from the RewriteCond
. You may be sticking the whole match as the user part, assuming the rewriter doesn't choke on the fact that $2
is a dangling backreference.
这篇关于hostgator:通配符子域到URL的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!