.htaccess RewriteRule不覆盖URL

时间:2015-01-15 23:13:16

标签: .htaccess shared-hosting

我有这个.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

编辑:我确实用。"拒绝所有"来测试.htaccess,它确实有效。

1 个答案:

答案 0 :(得分:3)

您当前的重写规则只能解析一个漂亮的网址。它不会将实际的/products.php网址转换为漂亮的网址。您需要有一个明确的规则

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]