【问题标题】:Htaccess only for friendly urlsHtaccess 仅适用于友好的 url
【发布时间】:2016-01-16 18:18:26
【问题描述】:

我怎样才能只为友好的 url 重写 htaccess? 我有

RewriteRule ^products/([0-9]+)?$ show_a_product.php?product_id=$1    [NC,L]

我希望 ONLY 重定向像 /products/1 这样的网址,但它也适用于 /show_a_product.php?product_id=1

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    你可以有另一个规则来阻止/show_a_product.php?product_id=1 URI:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} /show_a_product\.php[?/\s] [NC]
    RewriteRule ^ - [L,R=404]
    
    RewriteRule ^products/(\d+)/?$ show_a_product.php?product_id=$1 [QSA,NC,L]
    

    【讨论】:

    • 但是当用户输入show_a_product.php 之类的内容时它仍然有效,我认为这应该返回 404 页面,而不是禁止页面。
    猜你喜欢
    • 1970-01-01
    • 2015-03-04
    • 2013-08-31
    • 2012-06-03
    • 1970-01-01
    • 2017-09-20
    • 2012-04-25
    • 1970-01-01
    相关资源
    最近更新 更多