繁体   English   中英

如何重写 url 删除 slug /product/

[英]How to rewrite url remove slug /product/

我有一个示例链接:

https://stackoverflow.com/test/index.php/product/01-00030am-1a1y

我想删除 /product 它变成

https://stackoverflow.com/test/index.php/01-00030am-1a1y

这是.htaccess

RewriteCond %{HTTP_HOST}
RewriteRule ^test/index.php/product/(.*)$ test/index.php/$2 [R=301]

但它永远不起作用,如何解决它

我相信它是$1 $2而不是$2

$2指的是您尚未设置的第二个匹配组。 尝试:

RewriteCond %{HTTP_HOST}
RewriteRule ^test/index.php/product/(.*)$ /test/index.php/$1 [R=301,L]

[L] 标志导致 mod_rewrite 停止处理规则集。 在大多数情况下,这意味着如果规则匹配,则不会处理其他规则。 文档

查看此处此处了解有关 .htaccess 规则的更多信息。

同时请确保您有mod_rewrite的on ,否则将无法正常工作。 如果没有,我想您可以将它添加到您的 .htaccess 中

RewriteEngine On

RewriteCond %{HTTP_HOST}
RewriteRule ^test/index.php/product/(.*)$ /test/index.php/$1 [R=301,L]

作为替代方案,如果您使用 WooCommerce,请尝试使用woo-permalink-manager插件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM