使用HTACCESS将.html文件名更改为$ _GET [] id变量

时间:2015-12-23 12:13:26

标签: html .htaccess get

我想要达到的目标是:

如果有一个以:

结尾的网址
_2.html 

或任何其他数字:

_3.html , _4.html

将其更改为

?page_number_0=2 

示例:

http://example.com/top-10-answers/top-10-answer_2.html
http://example.com/top-10-answers/top-10-answer_3.html
http://example.com/top-10-answers/top-10-answer_4.html

...

到:

http://example.com/top-10-answers/?page_number_0=2
http://example.com/top-10-answers/?page_number_0=3
http://example.com/top-10-answers/?page_number_0=4

.....

1 个答案:

答案 0 :(得分:1)

尝试:

RewriteEngine On

RewriteCond %{THE_REQUEST} /.+_([0-9]+)\.html [NC]
RewriteRule ^ /top-10-answers/?page_number_0=%1 [NC,L,R]

%1是RewriteCond中正则表达式的一部分,它是([和])之间捕获的部分。