简体   繁体   English

Apache htaccess 从 301 重定向中排除特定 URL

[英]Apache htaccess exclude specific URL from 301-redirect

On a apache system i added a redirect from the old server to the new one with this .htaccess:在 apache 系统上,我使用此 .htaccess 添加了从旧服务器到新服务器的重定向:

redirect 301 / http://www.new-domain.com/redirect.php?q=

But i want to exclude this redirect for this URL:但我想排除这个 URL 的重定向:

http://domain.com/index.php/admin/

Every request to the old admin-area having this part in the URL "/index.php/admin" shall remain on the old server and not being redirected to the new one.在 URL "/index.php/admin" 中包含此部分的旧管理区域的每个请求都应保留在旧服务器上,而不会被重定向到新服务器。

How to achieve that?如何做到这一点?

You can use mod_rewrite rule for that instead of Redirect that doesn't allow regex:您可以使用mod_rewrite规则代替不允许正则表达式的Redirect

RewriteEngine On

RewriteRule !^index\.php/admin http://www.new-domain.com/redirect.php?q=%{REQUEST_URI} [L,NE,R=302]

You can wrap the Redirect directive inside anIf您可以将Redirect指令包装在If

<If %{REQUEST_URI} != "/index.php/admin/">
    Redirect ...
</If>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM