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
Php URL重写和重定向规则_Php_.htaccess_Mod Rewrite - Fatal编程技术网

Php URL重写和重定向规则

Php URL重写和重定向规则,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我需要帮助在我自己的URL重写。我的URL结构是 我希望它是什么样子的 到目前为止,我尝试的是在我的.htaccess文件中 ErrorDocument 404 /myproject/notfound.php Options +FollowSymlinks RewriteEngine on RewriteBase /myproject/ RewriteRule ^products/([^/]+)$ products-detail.php?id=$1 [QSA] 上面的规则在结尾没有尾随斜

我需要帮助在我自己的URL重写。我的URL结构是

我希望它是什么样子的

到目前为止,我尝试的是在我的.htaccess文件中

ErrorDocument 404 /myproject/notfound.php

Options +FollowSymlinks
RewriteEngine on
RewriteBase /myproject/

RewriteRule ^products/([^/]+)$ products-detail.php?id=$1 [QSA]
上面的规则在结尾没有尾随斜杠的情况下运行良好,但我确实希望在结尾有斜杠

更多信息:


如果非重写请求被重定向到重写请求,那就太好了。谢谢:)

您需要一个新的重定向规则:

ErrorDocument 404/myproject/notfound.php

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /myproject/

RewriteCond %{THE_REQUEST} /products-detail\.php\?id=([^\s&]+) [NC]
RewriteRule ^ products/%1? [R=302,L,NE]

RewriteRule ^products/([^/]+)/?$ products-detail.php?id=$1 [NC,L,QSA]

真棒,真正的快速修复。