首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在RewriteRule中使用RewriteCond HTTP_HOST的匹配部分?

问如何在RewriteRule中使用RewriteCond HTTP_HOST的匹配部分?
EN

Stack Overflow用户
提问于 2012-09-14 05:14:34
回答 1查看 1.7K关注 0票数 0

我有一个需要匹配的域名与正则表达式的一部分,并重定向到一个不同的域名与匹配的部分是文件名的一部分。

例如,在this-is.com上的htaccess中:

代码语言:javascript
复制
this-is-a-test.com redirects to this-is.com/test.htm
this-is-a-fish.com redirects to this-is.com/fish.htm
this-is-a-duck.com redirect to this-is.com/duck.htm

到目前为止,我已经尝试了以下几种方法:

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{HTTP_HOST} ^this-is-a-(.*).com$                                                                                                                                         
RewriteRule (.*) http://this-is.com/test.htm [L]

但这并不起作用,因为RewriteRule只处理查询字符串部分,而不处理主机部分。

如何在RewriteRule中使用RewriteCond的匹配部分?

EN

回答 1

Stack Overflow用户

发布于 2012-09-14 05:27:10

解决了!

为了便于将来参考,您应该使用百分号表示RewriteCond匹配:

代码语言:javascript
复制
RewriteCond %{HTTP_HOST} ^this-is-a-(.*).com$
RewriteRule (.*) http://this-is.com/%1.htm [L] 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12414893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档