如何重定向除一个目录之外的所有目录(htaccess)

时间:2022-01-15 15:19:54

I tried to redirect the entire subdomain content to another domain but leave wp-admin folder of that subdomain stay.

我尝试将整个子域内容重定向到另一个域,但保留该子域的wp-admin文件夹。

REDIRECT sub.example.com TO example.org BUT NOT sub.example.com/wp-admin

将sub.example.com重定向到example.org但不是sub.example.com/wp-admin

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com/(?!wp-admin) [NC]
RewriteRule ^(.*) http://www.example.org [L,R=301]

that won't work

这是行不通的

1 个解决方案

#1


2  

You cant match against uri in %{HTTP_HOST} condition, you need to match against uri in RewriteRule directive

您无法在%{HTTP_HOST}条件下与uri匹配,您需要在RewriteRule指令中与uri匹配

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com [NC]
RewriteRule ^((?!wp-admin).*)$ http://www.example.org%{REQUEST_URI} [L,R=301]

#1


2  

You cant match against uri in %{HTTP_HOST} condition, you need to match against uri in RewriteRule directive

您无法在%{HTTP_HOST}条件下与uri匹配,您需要在RewriteRule指令中与uri匹配

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com [NC]
RewriteRule ^((?!wp-admin).*)$ http://www.example.org%{REQUEST_URI} [L,R=301]