.htaccess重写但它得到错误的参数

时间:2015-07-14 05:06:48

标签: apache .htaccess mod-rewrite

这是我的链接

A.http://domaim/category/para1
B.http://domaim/category/para1/
C.http://domaim/category/para1/para2
D.http://domaim/category/para1/para2/

paramater是一个字符串(urlencode或其他)

那是我的.htacess

RewriteEngine on
RewriteRule ^category/([^/]+)$ category.php?mid=$1
RewriteRule ^category/([^/]+)/([^/]+)$ category.php?mid=$1&sid=$2

A和C得到正确的参数,但B和D得到页面没有找到!!错误404

然后我尝试修改.htacess但错误

RewriteEngine on
RewriteRule ^category/(.*)$ category.php?mid=$1
RewriteRule ^category/([^/]+)/(.*)$ category.php?mid=$1&sid=$2

2 个答案:

答案 0 :(得分:1)

检查结尾“/”:

gulp-inject-string

答案 1 :(得分:0)

使用您最初使用的规则,但在static String toString(Object value) { if (value instanceof String) { return (String) value; } else if (value != null) { return String.valueOf(value); } return null; } 之前添加/?。这使得尾部斜杠可选。

$

推荐:为了防止重复内容,最好先从URI修剪尾部斜杠:

RewriteEngine on
RewriteRule ^category/([^/]+)/?$ category.php?mid=$1
RewriteRule ^category/([^/]+)/([^/]+)/?$ category.php?mid=$1&sid=$2