的.htaccess:"永久重定向和QUOT;回退到一个"重写规则"重写、退到、重定向、规则

2023-09-02 09:59:07 作者:年轻不是罪。

我有一个网上商店,我们切换子目录。从/店根/。还有些产品展示和分类名更改。

i have a webshop where we switch the subdirectory. From "/shop" to the root "/". Also some Product- and category-names change.

我要重定向一些特定的网址,较新的。例如: www.domainname.de/shop/product_abc www.domainname.de/product_abc_v2 对于这一点,我使用.htaccess文件的永久重定向声明。

I want to redirect some specific URLs to newer ones. For Example: www.domainname.de/shop/product_abc to www.domainname.de/product_abc_v2 For this i use the Redirect Permanent declaration in the .htaccess File.

在下一步我希望有一个后备的所有其他URL's女巫看起来像这样: www.domainname.de/shop/XXXXX

In the next Step i want a Fallback for all other URL´s witch looking like this: www.domainname.de/shop/XXXXX.

所以,我写这篇文章重写规则:

So i write this Rewrite Rule:

RewriteCond %{REQUEST_URI} ^/shop/(.*)
RewriteRule ^(.*)$ http://www.domainname.de/ [r=301,L]
RewriteRule ^(.*)/$ $1 [R=301,L]

现在我的问题:我把重写规则的.htaccess文件的底部,使永久重定向 - code将用于重写规则使用之前。但无论如何重写规则总是被。是否有此问题的任何解决方案?!

Now my problem: I put the Rewrite Rule to the bottom of the .htaccess File so that the Redirect Permanent-Code would used before the Rewrite Rule is used. But anyway the Rewrite Rule is always taken. Is there any Solution for this problem?!

非常感谢!

推荐答案

解决方案是只使用了mod_rewrite。当你混合mod_alias中(重定向永久)和mod_rewrite的(重写规则 )一起指令,两个模块都将得到适用于每一个网址,并在这两个得到应用的情况下,你结束了一些意外的行为。

The solution is to use only mod_rewrite. When you mix mod_alias (Redirect Permanent) and mod_rewrite (RewriteRule) directives together, both modules will get applied to every URL, and in cases where both get applied, you end up with some unexpected behavior.

您需要做的第一件事就是修改重定向重写

The first thing you need to do is change the Redirect to Rewrite:

Redirect Permanent /shop/product_abc /shop/product_abc_v2

RewriteRule ^shop/product_abc(.*)$ /shop/product_abc_v2$1 [L,R=301]

然后,你需要确保新规则是在正确的地方。订单事宜与重写规则。

Then you need to make sure the new rule is in the right place. The order matters with rewrite rules.