.htaccess重写规则未重写URL
我有这个.htaccess,它基本上是用来关闭我的链接的.htaccess重写规则未重写URL,.htaccess,shared-hosting,.htaccess,Shared Hosting,我有这个.htaccess,它基本上是用来关闭我的链接的 http://www.dsbigiena.ro/products.php?product-id=Colac-wc-cu-folie-de-plastic-cu-actionare-manuala-prin-buton 到 不幸的是,它没有这样做 我写错了吗 RewriteEngine On RewriteBase / RewriteRule ^([^/]*)/$ /products.php?product-id=$1 [L] Rewri
http://www.dsbigiena.ro/products.php?product-id=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,它很有效。您当前的重写规则只能解析一个漂亮的URL。它不会将实际的
/products.php
URL单独转换为漂亮的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塑料cu操作手册A prin buton
Alex,您只需将?
添加到第一条重写规则
。这将删除漂亮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]