首页 > 解决方案 > 使用 htaccess 重写规则

问题描述

我想在不同的 URL 中重定向以下 URL。请帮助我。

第一个网址:

http://localhost/magento2-ce/images/ 重定向到 http://localhost/magento2-ce/

第二个网址:

http://localhost/magento2-ce/images/9781601525871/ 重定向到 http://localhost/magento2-ce//book/landing/detailedview?itemcode=9781601525871J

我做了什么?

我尝试了以下解决方案以使第二个 URL 正常工作。

RewriteRule ^images/([0-9]+)/ http://localhost/magento2-ce/book/landing/detailedview?itemcode=$1J [R=301,NC,L]

但是,当我将以下规则应用于第一个 URL 重定向时,上面的重写规则不起作用。

RewriteRule ^images/  http://localhost/magento2-ce/ [R=301,NC,L]

标签: apache.htaccessmod-rewriteurl-rewritingurl-redirection

解决方案


您是否尝试过从一个或两个规则中删除 L(最后一个)标志? https://httpd.apache.org/docs/2.4/rewrite/flags.html


推荐阅读