.htaccess重写规则:删除斜杠

时间:2016-11-02 16:59:31

标签: php apache .htaccess mod-rewrite url-rewriting

当前.htaccess

RewriteRule ^([a-z-]+)/([a-z-]+)$ /r.php?catname=$1&subcatname=$2 [L]

RewriteRule ^([a-z-]+)/([a-z-]+)/([0-9]+)/$ /r.php?catname=$1&subcatname=$2&page=$3 [L]

RewriteRule ^([a-z-]+)$ /r.php?catname=$1 [L]

RewriteRule ^([a-z-]+)/([0-9]+)/$ /r.php?catname=$1&page=$2 [L]

我的输出目前是:

www.domain.com/$catname                  =>      www.domain.com/blog
www.domain.com/$catname/&subcatname/         =>      www.domain.com/blog/extra/
www.domain.com/$catname/&subcatname/3/       =>      www.domain.com/blog/extra/3/
www.domain.com/$catname/2/        =>      www.domain.com/blog/extra/2/  

我希望我的输出为:

www.domain.com/$catname                       =>      www.domain.com/blog
www.domain.com/$catname/&subcatname              =>      www.domain.com/blog/extra
www.domain.com/$catname/&subcatname/&page        =>      www.domain.com/blog/extra/1
www.domain.com/$catname/&page                   =>      www.domain.com/blog/1

我想它所以没有网址有一个尾随斜线。

1 个答案:

答案 0 :(得分:0)

更新您的RewriteRule,希望您能获得预期的输出:

RewriteRule ^([a-z-]+)/([a-z-]+)$ /r.php?catname=$1&subcatname=$2 [L]

RewriteRule ^([a-z-]+)/([a-z-]+)/([0-9]+)$ /r.php?   catname=$1&subcatname=$2&page=$3 [L]

RewriteRule ^([a-z-]+)$ /r.php?catname=$1 [L]

RewriteRule ^([a-z-]+)/([0-9]+)$ /r.php?catname=$1&page=$2 [L]