【问题标题】:Using HTACCESS to change .html files names into $_GET[] id variables使用 HTACCESS 将 .html 文件名更改为 $_GET[] id 变量
【发布时间】:2015-12-23 12:13:25
【问题描述】:

我想要实现的是:

如果有一个以:结尾的url

_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

.....

【问题讨论】:

    标签: html .htaccess get


    【解决方案1】:

    试试:

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

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

    【讨论】:

    • 谢谢 Starkeen 它只适用于数字 2,因为第二个 RewriteRule 有一个静态数字:RewriteRule ^ /top-10-answers/?page_number_0=2 [NC,L,R] 有没有办法第二条规则是动态的并采用上述规则编号?
    • 或者我们可以为从 2 到 10 的每个数字制定 9 条规则吗?
    • @luarbballa 不,只需 1 条规则就足够了。
    • @Sarkeen 它现在可以完全运行,但是有一个问题,现在它只打开 .html 文件所在的根文件夹,当我访问它们时,规则适用但它不打开文件:(
    猜你喜欢
    • 2020-07-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    相关资源
    最近更新 更多