我正在尝试编辑我的.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]
答案 0 :(得分:1)
尝试将以下内容添加到站点根目录中的.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.com
和example.com
位于具有相同根文件夹的同一服务器上。