php - .htaccess 重定向匹配。匹配除一个单词之外的字符串

标签 php regex .htaccess redirect

我需要有关 RedirectMatch Regex 指令的帮助。

我需要将以下 URL 重定向如下:

RedirectMatch 301 ^/category/category-title/(.+)(!?/page/)$ http://example.com/product/category-title/$1

我想要的结果是重定向到指定的产品标题,除非找到单词页面:

http://example.com/category/category-title/some-product-title-here

重定向至

http://example.com/product/category-title/some-product-title-here

以下内容不匹配: http://example.com/category/category-title/page/23

编辑:

我有一个具有以下规则的重定向循环:

RedirectMatch 301 ^/categorie/boulangerie-et-patisserie/((?!/page/).+)$ http://recyclageindustriel.com/produit/boulangerie-et-patisserie/$1

RedirectMatch 301 ^/produit/boulangerie-et-patisserie/page/(.*)$ http://recyclageindustriel.com/categorie/boulangerie-et-patisserie/page/$1

感谢您的帮助!

最佳答案

您的否定先行语法不正确,而且位置也错误。

试试这个:

RedirectMatch 301 ^/categorie/boulangerie-et-patisserie/(?!page/)(.+)$ /produit/boulangerie-et-patisserie/$1

RedirectMatch 301 ^/produit/boulangerie-et-patisserie/page/(.*)$ /categorie/boulangerie-et-patisserie/page/$1

正确的否定先行语法是(?!page/)

关于php - .htaccess 重定向匹配。匹配除一个单词之外的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33550099/

相关文章:

php - Laravel 将我的 CRUD 迁移到另一个项目

php - 在 Windows 中向 PHP 添加 Mysqli 扩展时出错

python正则表达式帮助

.htaccess - htaccess 全部重写为index.html

PHP:将图像从文件夹上传到MySQL数据库

php - 关于 is_resource() 函数的快速 PHP 查询

regex - 删除字符串中单个字符之间的空格

java - 删除Java中的尾随零

.htaccess - 只允许通过 VPN 私有(private)访问网站

php - 如何从 Symfony2 URL 中删除 "web/app_dev.php"?