【发布时间】:2014-06-13 11:01:17
【问题描述】:
我有这个当前的 url 重写:
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
现在我需要补充一点,每个空格都被替换为“-”,但是如何将其添加到我的重写中?这样可以吗?
【问题讨论】:
-
你的意思是在重写规则中替换空格?使用 mod_rewrite,您无法进行替换。您应该在 php 代码中执行此操作。
我有这个当前的 url 重写:
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
现在我需要补充一点,每个空格都被替换为“-”,但是如何将其添加到我的重写中?这样可以吗?
【问题讨论】:
您可以在重写规则中接受空格:
RewriteRule ^([(a-zA-Z0-9_-]|\s)+)$ index.php?id=$1
然后在 index.php 中你必须用下划线替换空格:
preg_replace('/\s+/', '_', $id);
【讨论】: