![](/img/trans.png)
[英]how to remove %20 at the end of the url in opencart using htaccess
[英]How to remove a number from the end of an URL using .htaccess?
我有很多以-xxx結尾的URL,其中xxx是介於000和999之間的數字。例如:
http://a.com/imagea-000
http://a.com/category1/imageb-002
http://a.com/category1/category2/imagec-999
如何在.httaccess中指定RewriteCond / RewriteRule以刪除數字,包括url末尾的“-”? 因此,最終的URL如下所示:
http://a.com/imagea
http://a.com/category1/imageb
http://a.com/category1/category2/imagec
您可以在DOCUMENT_ROOT/.htaccess
文件中使用以下代碼:
RewriteEngine On
RewriteRule ^(.+?)-\d+/?$ /$1 [L,R=302]
-\\d+/?$
將匹配連字符,后跟1或數字和URI末尾的可選斜杠。 (.+?)
將匹配上述模式之前的任何內容並將其捕獲為組#1 R=302
替換為R=301
。 在測試mod_rewrite規則時,避免使用R=301
(永久重定向)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.