Php 在.htaccess中应用多个301重定向

Php 在.htaccess中应用多个301重定向,php,.htaccess,redirect,Php,.htaccess,Redirect,在根级别的.htaccess文件中,我尝试了这个301重定向代码,它可以工作:- redirect 301 /en/about/product.html http://mydomain.com/shop? 然而,当我尝试复制句子时,对于其他页面,它总是以服务器错误500结束 实际上,我应该如何在.htaccess中包含10条重定向规则?试试这个 RewriteEngine On RewriteRule ^/en/about/product\.html?(.*)$ http://mydoma

在根级别的.htaccess文件中,我尝试了这个301重定向代码,它可以工作:-

redirect 301  /en/about/product.html  http://mydomain.com/shop?
然而,当我尝试复制句子时,对于其他页面,它总是以服务器错误500结束

实际上,我应该如何在.htaccess中包含10条重定向规则?

试试这个

RewriteEngine On
RewriteRule ^/en/about/product\.html?(.*)$ http://mydomain.com/shop/?$1 [R=301,L,S=1]

#other page

RewriteRule ^/en/about/product1\.html?(.*)$ http://mydomain.com/shop1/?$1 [R=301,L]

好的,为了实现最佳的可移植性,我建议您键入与Apache
mod_alias
文档中显示的指令完全相同的指令,但除此之外,它们是正确的

Redirect 301 /the_old_page.htm http://example.com/the-new-page.htm
Redirect 301 /the_old_page2.htm http://example.com/the-new-page2.htm
Redirect 301 /the_old_page3.htm http://example.com/the-new-page3.htm
现在,您可能不需要50条规则。下面是一个示例,将示例URL视为真正的URL:

RedirectMatch 301 ^/the_old_([^.]+)\.htm$ http://example.com/the-new-$1.htm
这将只使用一个指令而不是五十个指令将表单
“/the_old\uuu.htm”
的所有URL重定向到
“/the new-.htm”

如果您的旧URL具有这样的通用性,您可以利用它来减少需要编写、测试和维护的重定向指令的数量


希望能有帮助。

日志里写了什么?我观察到的模式是,每个句子都以“重定向301 xxxx”开头。然而,当我尝试这个模式时,当有超过1个时,它将以服务器错误结束。有什么特别的事情需要注意吗?事实上,我正在使用opencart。模式。。你唯一需要集中精力的事。。错误的模式可能导致错误的结果。。