的.htaccess:"永久重定向和QUOT;回退到一个"重写规则" [英] .htaccess: "redirect permanent" with fallback to a "RewriteRule"

查看:130
本文介绍了的.htaccess:"永久重定向和QUOT;回退到一个"重写规则"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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的(重写规则 <$ C C $>)一起指令,两个模块都将得到适用于每一个网址,并在这两个得到应用的情况下,你结束了一些意外的行为。

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.

这篇关于的.htaccess:&QUOT;永久重定向和QUOT;回退到一个&QUOT;重写规则&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆