[英].htaccess RewriteRule change underscore to dash
I have a ReWrite rule in my .htaccess file right now: 我的.htaccess文件中现在有一个ReWrite规则:
RewriteRule ^item/?([a-zA-Z0-9_]+)?/?([a-zA-Z0-9_]+)?/?$ static/items.php?a=$1&b=$2 [NC,L]
It will pick any items that have an underscore: 它将选择任何带有下划线的项目:
item/new_item/new_order
However, I need to change from underscore to dashes to make it: 但是,我需要将其从下划线更改为破折号:
item/new-item/new-order
If I simply make a change in RewriteRule string it breaks it. 如果我只是在RewriteRule字符串中进行更改,它将破坏它。 Not sure how to fix that.
不知道如何解决。
RewriteRule ^item/?([a-zA-Z0-9-]+)?/?([a-zA-Z0-9-]+)?/?$ static/items.php?a=$1&b=$2 [NC,L]
This is fairly tricky stuff but can be done using following Rewrite
rules: 这是相当棘手的事情,但是可以使用以下
Rewrite
规则来完成:
RewriteEngine On
# first replace each _ by - recursively
RewriteRule ^(item)/([^_]*)_(.*)$ /$1/$2-$3 [L,NC]
# now usual stuff to forward request to static/item.php
RewriteRule ^(item)/([^_/]*)/?([^_/]*)/?$ static/$1.php?a=$2&b=$3 [L,QSA,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.