【发布时间】:2012-02-14 19:27:13
【问题描述】:
我正在尝试编辑我的 .htaccess 文件以执行以下操作: 1)判断HTTP_HOST是否不是我自己的域,example.com 2)判断是否是otherdomain.com/admin/_anything_here_
/admin/ 是我正在寻找的特定文件夹,然后我不在乎它后面的内容(但我确实需要将它保留在那里)。所以基本上任何以 /admin/ 作为第一个文件夹并且不是 example.com 的东西都应该重写到 otherdomain.com/admin/_anything_still_here_
据我了解,使用 (.*)$ 将“存储”_anything_here_ 部分并允许我将其与 $1 一起使用。
到目前为止我有这个,但它没有完全工作:
RewriteCond ^%{HTTP_HOST}+(/admin.*)$ !^([^.]+\.)*example\.com+(/admin.*)
RewriteRule (.*)$ rewrite/to/here$1/ [L]
【问题讨论】:
-
我不明白
/admin...被改写成什么。举个例子。对于otherdomain.com/admin/_anything_here_=>otherdomain.com/admin/_anything_still_here_ -
抱歉,有点不清楚。基本上,otherdomain.com/admin/_anything_here_ 应该重写为 rewrite/to/here$1/,其中 $1 是 anything_here。我有 anything_still_here 的原因只是为了表明我不想删除 /admin/ 之后的内容。这有帮助吗?
-
不多。假设 URL 是这样的:
otherdomain.com/admin/site/old。这应该改写成什么? -
它会重写到 otherdomain.com/rewrite/to/here/admin/site/old
标签: regex apache .htaccess mod-rewrite redirect