htaccess 子域到页面的重写规则 [英] htaccess Rewrite Rule for subdomain to page

查看:20
本文介绍了htaccess 子域到页面的重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个页面位于:

Currently I have a page residing at:

http://www.example.com/site/page

在我的 htaccess 中,我有当前的规则:

In my htaccess I have the current rule:

RewriteRule ^site/(.*)$ retailer.php?linklabel=$1 [QSA]

让该页面的 URL 成为它自己的子域的规则是什么样的:

What would the rule look like to have the URL for that page become it's own subdomain:

http://page.example.com

感谢您的帮助!!

到目前为止,我已经尝试了以下规则,但没有奏效:

So far I have tried the following rule which hasn't worked:

RewriteRule http://(.*)$.example.com retailer.php?linklabel=$1 [QSA]

也许我需要先在 cpanel 中做一些关于通配符子域的事情?我不太确定...

Maybe I need to do something in cpanel first regarding a wildcard subdomain? I'm not too sure...

推荐答案

尝试:

RewriteCond %{HTTP_HOST} !^www.[NC]
RewriteCond %{HTTP_HOST} ^(.+?).example.com$ [NC]
RewriteRule ^$ retailer.php?linklabel=%1 [L,QSA]

你不能在 RewriteRule 中匹配主机,所以你需要在 RewriteCond 中匹配 %{HTTP_HOST} 变量,然后使用 %1 反向引用来获得匹配.

You can't match against the host in a RewriteRule, so you'll need to do it against the %{HTTP_HOST} var in a RewriteCond, then use the %1 backreference to get that match.

目前这只会匹配完全是 / 的 URI.所以它不会与 http://page.example.com/something 匹配,除非你将正则表达式从 ^$ 更改为 ^something$.

This will currently only match against URI's that are exactly /. So it won't match against http://page.example.com/something unless you change the regular express at from ^$ to ^something$.

这篇关于htaccess 子域到页面的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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