htaccess使用空格获取值


example.com/search/search+something I want to like this search but its not work

example.com/search/.htaccess

<Files .htaccess>
order allow,deny
</Files>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /search/
RewriteRule ^(w+)(?:/[^/]+)?/?$ load.php?q=$1 [L,QSA]
RewriteRule ^(w+)/[^/]+/[^/]+/([0-9]+)/?$ load.php?q=$1&p=$2 [L,QSA]

如何修复它…如果我像这样键入example.com/search/songs,它就工作了。但在songs之后添加一些带有空格或(+(的内容不起作用,并显示404页。。ex :(example.com/search/songs+video)

w更改为[^/],以便可以匹配空格,但不能匹配斜线。URI中的编码空间在被重写规则中的模式匹配之前会被解码:

RewriteRule ^([^/]+)(?:/[^/]+)?/?$ load.php?q=$1 [L,QSA]

如果字符串在load.php脚本中以%20结尾,您可能还需要在方括号中添加NE标志。

最新更新