Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess重写规则未重写URL_.htaccess_Shared Hosting - Fatal编程技术网

.htaccess重写规则未重写URL

.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

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