HTTP_HOST 的 .htaccess 正则表达式后跟特定文件夹

发布于 2025-01-05 18:18:02 字数 509 浏览 3 评论 0原文

我正在尝试编辑 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑寡妇 2025-01-12 18:18:02

尝试将以下内容添加到站点根目录中的 .htaccess 文件中。

您需要将 somefolder 替换为您要重写的实际文件夹。

RewriteEngine on
RewriteBase / 

#if its not example.com
RewriteCond %{HTTP_HOST} !example\.com$ [NC] 
#if its admin folder, rewrite it to somefolder
RewriteRule ^(admin/.*)$  somefolder/$1[L,NC] 

上面假设 otherdomain.comexample.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 to

RewriteEngine on
RewriteBase / 

#if its not example.com
RewriteCond %{HTTP_HOST} !example\.com$ [NC] 
#if its admin folder, rewrite it to somefolder
RewriteRule ^(admin/.*)$  somefolder/$1[L,NC] 

The above assumes that otherdomain.com and example.com are on the same server with the same root folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文