嗨我在我的htaccess中有这个代码
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+single\.php\?title=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$single.php?title=$1 [NE,L,QSA]
我在网址中有空格,需要用短划线( – )替换它们
我怎样才能做到这一点;
这是我要测试的一个页面
http://www.einfogarden.com/%D8%B1%D8%AC%D9%8A%D9%85%20%D8%A7%D9%84%D8%AA%D9%85%D8%B1%20%D9%88%D8%A7%D9%84%D8%AD%D9%84%D9%8A%D8%A8
解决方法:
你有这样的规则:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+single\.php\?title=([^\s&]+) [NC]
RewriteRule ^ %1/? [R=302,L,NE]
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(.*?)[^/][?\s]
RewriteRule [^/]$%{REQUEST_URI}/ [L,R=301]
# convert %20 to -
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [N,NE]
RewriteRule "^(\S*) (\S*)$" $1-$2 [L,R=302,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$single.php?title=$1 [NE,L,QSA]
标签:htaccess,php
来源: https://codeday.me/bug/20191001/1839809.html