使用重写规则更改路径中的最后一个元素

时间:2014-09-07 10:52:46

标签: regex apache .htaccess mod-rewrite


我需要使用重写规则创建重定向,该规则重写路径" / page-2 "进入" ?start = 1 "。例如:

http://mysite/article/page-2


需要改为:

http://mysite/article?start=1


尝试:

RewriteRule */page-2$ ?start=1 [R=301,L]

似乎不起作用。有帮助吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

您需要在根目录中使用此规则.htaccess:

RewriteEngine On

RewriteRule ^article/page-2/?$ /article/?start=1 [R=301,L,NC]

参考:Apache mod_rewrite Introduction

Apache mod_rewrite Technical Details