htaccess用空格获得价值

时间:2014-04-10 01:32:32

标签: php .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)

1 个答案:

答案 0 :(得分:2)

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

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

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