【问题标题】:how to write url parameter to .htaccess如何将url参数写入.htaccess
【发布时间】:2011-12-03 04:11:35
【问题描述】:

来自http://mardagz.net/view.php?year=2011&month=12&title=dear-christmas

mySQL 查询

SELECT * FROM tbl_post WHERE year=2011 AND month=12 AND title='dear-christmas'

[我的帖子将显示亲爱的圣诞节标题]

但我想重写 致http://mardagz.net/2011/12/dear-christmas

保护... :)

【问题讨论】:

    标签: php mysql .htaccess mod-rewrite


    【解决方案1】:

    这应该有效(注意:在这条规则中,我强制年份以“20”开头,这意味着它将适用于 2000 年到 2099 年之间的年份(我猜这对你来说应该足够了)):

    Options +FollowSymLinks
    
    RewriteEngine On
    RewriteRule ^20([0-9]{2})/([0-9]{1,2})/([a-z-]+) view.php?year=$1&month=$2&title=$3 [QSA,NC,L]
    

    请告诉我它是否有效

    【讨论】:

    • 我希望我不会活那么 ;)
    【解决方案2】:

    尝试类似:

        Options +FollowSymLinks
    
        RewriteEngine On
        RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ view.php?year=$1&month=$2&title=$3
    

    【讨论】:

    • 仅供参考,我认为如果没有尾部斜杠,那会失败。
    猜你喜欢
    • 1970-01-01
    • 2011-11-20
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    相关资源
    最近更新 更多