现代重写:更换所有下划线(_)与连字符( - ) [英] Mod Rewrite : Replace all _ (underscore) with - (hyphen)
本文介绍了现代重写:更换所有下划线(_)与连字符( - )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在每个URL的所有_(下划线),以被替换 - (连字符)
I need to have all _ (underscores) in every url to be replaced with - (hyphens)
我目前做这种方式,但在寻找这样做的更简单的方法,所以我不必每一个URL获取更长的时间添加一行。
I currently do it this way, but am looking for a more simpler way of doing this so I do not have to add a line every time a url gets longer.
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)-([^.]+)-([^.]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6_$7_$8_$10 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)-([^.]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6_$7_$8_$9 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6_$7_$8 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6_$7 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4 [L]
RewriteRule ^([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3 [L]
RewriteRule ^([^_]+)-([^.]+)$ index.php?/$1_$2 [L]
感谢。
推荐答案
sedhyphen.sh
:
#!/bin/sh
sed -u 's/_/-/g'
的httpd CONF:
httpd conf:
RewriteMap sed-hyphen prg:sedhyphen.sh
RewriteRule ^(.*)$ index.php?/${sed-hyphen:$1} [L]
确保sedhyphen.sh设置可执行的。
Make sure that sedhyphen.sh is set executable.
这篇关于现代重写:更换所有下划线(_)与连字符( - )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文