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 需要有关mod_重写的帮助吗_Php_.htaccess_Mod Rewrite - Fatal编程技术网

Php 需要有关mod_重写的帮助吗

Php 需要有关mod_重写的帮助吗,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我现在的代码是 RewriteRule ^(.*)$ index.php?pg=$1 [L,QSA] index.php?action=product shop.com/product index.php?action=product/add shop.com/product/add 现在我想给一些页面添加分页,比如 index.php?action=product&page=1&show=20 shop.com/product/1/20 index.php?action=p

我现在的代码是

RewriteRule ^(.*)$ index.php?pg=$1 [L,QSA]

index.php?action=product shop.com/product
index.php?action=product/add shop.com/product/add
现在我想给一些页面添加分页,比如

index.php?action=product&page=1&show=20 shop.com/product/1/20
index.php?action=product/add&page=1&show=20 shop.com/product/add/1/20
我该怎么做

RewriteEngine On

RewriteRule ^product$ index.php?action=product
RewriteRule ^product/add$ index.php?action=product/add
RewriteRule ^product/(\d+)/(\d+)$ index.php?action=product&page=$1&show=$2
RewriteRule ^product/add/(\d+)/(\d+)$ index.php?action=product/add&page=$1&show=$2


我建议你也去看看。我认为在这种情况下会更好。

分页通常通过常规get参数来完成-
shop.com/product?page=42
。没有任何理由想要将所有要由mod_rewrite处理的内容都移动。对于我来说,
product/1/20
什么也没说,而
product?page=1&show=20
是一个非常自我描述的url。Mod_rewrite与PHP无关,只是说。哇,谢谢你的重播,但我不能对每个文件都这样做。我有5-10个不同的操作,这意味着我必须为每个文件编写10条以上的重写规则。。另外,如果在我的代码中添加新操作,我必须为它添加一个重写规则,这对我来说似乎不是很灵活。这就是为什么我还添加了答案的链接。