HTTP_HOST 的 .htaccess 正则表达式后跟特定文件夹
我正在尝试编辑 .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]
I'm trying to edit my .htaccess file to do the following:
1) Determine if the HTTP_HOST is not my own domain, example.com
2) Determine if it is otherdomain.com/admin/_anything_here_
/admin/ is the specific folder I am looking for, then I don't care what comes after it (but I do need to keep it there). So basically anything that has /admin/ as the first folder and isn't example.com should rewrite to otherdomain.com/admin/_anything_still_here_
It's my understanding that using (.*)$ will "store" the _anything_here_ part and allow me to use it with $1.
I have this so far but it isn't working fully:
RewriteCond ^%{HTTP_HOST}+(/admin.*)$ !^([^.]+\.)*example\.com+(/admin.*)
RewriteRule (.*)$ rewrite/to/here$1/ [L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将以下内容添加到站点根目录中的
.htaccess
文件中。您需要将
somefolder
替换为您要重写的实际文件夹。上面假设
otherdomain.com
和example.com
位于同一文件夹中服务器具有相同的根文件夹。Try adding the following to the
.htaccess
file in the root directory of your site.You need to replace
somefolder
with the actual folder you want to rewrite toThe above assumes that
otherdomain.com
andexample.com
are on the same server with the same root folder.