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
HTACCES index.php参数_Php_.htaccess_Mod Rewrite_Url Rewriting_Rewrite - Fatal编程技术网

HTACCES index.php参数

HTACCES index.php参数,php,.htaccess,mod-rewrite,url-rewriting,rewrite,Php,.htaccess,Mod Rewrite,Url Rewriting,Rewrite,我的.htaccess文件有问题。 我的问题 当我使用以下url输入我的网页时: http://www.website.com/sys/module/photos/ http://www.website.com/sys/module/photos/add/10/ http://www.website.com/sys/module/photos/1/ 我可以通过以下url在该页面上添加一些照片: http://www.website.com/sys/module/photos/ http

我的.htaccess文件有问题。


我的问题

当我使用以下url输入我的网页时:

http://www.website.com/sys/module/photos/
http://www.website.com/sys/module/photos/add/10/
http://www.website.com/sys/module/photos/1/
我可以通过以下url在该页面上添加一些照片:

http://www.website.com/sys/module/photos/
http://www.website.com/sys/module/photos/add/10/
http://www.website.com/sys/module/photos/1/



现在我已经对index.php文件进行了分页,我想像这样进入页面:

http://www.website.com/sys/module/photos/
RewriteEngine On
RewriteRule add/(.*)/$ add.php?id=$1
RewriteRule ^$ index.php
RewriteEngine On
RewriteRule ^add/([0-9]+)/?$ add.php?id=$1 [L]
RewriteRule ^([0-9]+)/?$ index.php?page=$1 [L]
并使用以下url转到下一页:

http://www.website.com/sys/module/photos/
http://www.website.com/sys/module/photos/add/10/
http://www.website.com/sys/module/photos/1/


这是我的.htaccess文件

RewriteEngine On
RewriteRule add/(.*)/$ add.php?id=$1
RewriteRule (.*)/$ index.php?page=$1


但是如果我现在转到
http://www.website.com/sys/module/photos/add/10/
它将显示index.php文件的内容


如何解决此问题?

该.htaccess应如下所示:

http://www.website.com/sys/module/photos/
RewriteEngine On
RewriteRule add/(.*)/$ add.php?id=$1
RewriteRule ^$ index.php
RewriteEngine On
RewriteRule ^add/([0-9]+)/?$ add.php?id=$1 [L]
RewriteRule ^([0-9]+)/?$ index.php?page=$1 [L]
如评论中所述,
*
将匹配所有内容,包括url
http://www.website.com/sys/module/photos/add/10/


解决方案是将底部重写规则更改为仅与主页匹配(当您的路径为/)

我假设您的htaccess文件位于“照片”文件夹中,那么您的规则需要如下所示:

http://www.website.com/sys/module/photos/
RewriteEngine On
RewriteRule add/(.*)/$ add.php?id=$1
RewriteRule ^$ index.php
RewriteEngine On
RewriteRule ^add/([0-9]+)/?$ add.php?id=$1 [L]
RewriteRule ^([0-9]+)/?$ index.php?page=$1 [L]

您将缩小匹配范围,将捕获组限制为仅数字。

我认为这是因为规则
RewriteRule(.*)/$index.php?page=$1
<代码>*将基本匹配
http://www.website.com/sys/module/photos/add/10/
completely第二条规则使用了反向引用,但没有捕获组啊是的,我已经删除了反向引用