开发者

mod_rewrite search feature, problem with slash (404 error)

I'm trying to rewrite search results page url to something like /search/query-1.html but when I try searching for a keyword that has a slash "/" or "#" .. (e.g A/D) it returns a 404 error.

My .htaccess has开发者_开发问答 the following:

RewriteEngine on
RewriteRule ^search/(.*)-([0-9]+).html$ index.php?search=$1&page=$2 [L]

What can be the problem?

Thanks.


If you want Apache to accept encoded slashes like you mentioned in the comments, you'll have to enable it in your server configuration using the AllowEncodedSlashes directive:

AllowEncodedSlashes on

You likely don't have this enabled now, and the default behaviour in that case is for Apache to reject the request with a 404 response. You can only specify this directive in a server or virtual host context, so depending on your environment you might not be able to change this. As far as the encoded hash symbol goes, it shouldn't have any problem handling that.

However, it is likely that the hash is inserted into the query string decoded, which might cause some issues. If you find that to be the case and your Apache installation is new enough, you should add the B flag to your RewriteRule to ensure that the backreference is escaped appropriately:

RewriteRule ^search/(.*)-([0-9]+).html$ index.php?search=$1&page=$2 [B,L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜