【问题标题】:.htaccess RewriteRule not overriding URL.htaccess RewriteRule 不覆盖 URL
【发布时间】:2015-01-16 23:46:21
【问题描述】:

我有这个 .htaccess,它基本上应该把我的链接从

http://www.dsbigiena.ro/products.php?product-id=Colac-wc-cu-folie-de-plastic-cu-actionare-manuala-prin-buton

http://www.dsbigiena.ro/Colac-wc-cu-folie-de-plastic-cu-actionare-manuala-prin-buton/

不幸的是,它没有这样做。

我写错了吗?

RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)/$ /products.php?product-id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

编辑:我确实用“deny from all”测试了 .htaccess,它确实有效。

【问题讨论】:

    标签: .htaccess shared-hosting


    【解决方案1】:

    您当前的重写规则仅解析漂亮的 URL。它本身不会将实际的/products.php URL 转换为漂亮的。您需要为此制定明确的规则

    RewriteEngine On
    RewriteBase /
    
    # Redirects from a normal URL to a pretty one
    RewriteCond %{THE_REQUEST} \ /products\.php\?product-id=([^\ ]+) [NC]
    RewriteRule ^ /%1/? [L,R=301]
    
    # Resolves the pretty URL
    RewriteRule ^([^/]+)/?$ /products.php?product-id=$1 [QSA,L]
    

    【讨论】:

    • 有趣的是,它破坏了一切并将参数附加为后缀:http://www.dsbigiena.ro/Colac-wc-cu-folie-de-plastic-cu-actionare-manuala-prin-buton/?product-id=Colac-wc-cu-folie-de-plastic-cu-actionare-manuala-prin-buton
    • Alex,您只需将? 添加到第一个RewriteRule。这将去除漂亮 url 中的额外查询字符串。
    猜你喜欢
    • 1970-01-01
    • 2014-07-14
    • 2016-07-22
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多