使用htaccess将%20更改为 - 在URL中

时间:2016-07-26 06:47:58

标签: php .htaccess

我有 index.php 页&有一些帖子。当点击更多按钮被点击时,用户被重定向到 all.php ,其中包含完整的帖子。实际上, all.php 上的网址就像这样

  

http://localhost/project/all.php?rm=How%20to%20create%20jQuery%20Popup

我想将%20更改为-。 无论如何用 htaccess 来做到这一点。?

1 个答案:

答案 0 :(得分:0)

RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one (remove query string)
RewriteCond %{THE_REQUEST} \s/+content\.php\?page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]

# convert all space (%20) to hyphen
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [N,NE]
RewriteRule "^(\S*) (\S*)$" $1-$2 [L,R=302,NE]

# rewrite rule to call actual PHP handler
RewriteRule ^([^./]+)\.html$ content.php?page=$1 [L,QSA,NC]