Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Apache 重写规则,如果重写的文件不是index.php,则在规则与[L]匹配时不停止_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 重写规则,如果重写的文件不是index.php,则在规则与[L]匹配时不停止

Apache 重写规则,如果重写的文件不是index.php,则在规则与[L]匹配时不停止,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有一个相当复杂的.htaccess文件,其中有许多重写规则,到目前为止,除了我试图重写为一个不是index.php的文件外,所有这些规则都工作得很好 我尝试添加[L]我正在使用xampp轻松地运行它index.php和deleteItem.php都是有效文件。同样值得注意的是,根据我的规则,我不能再直接指向PHP文件了 这是我的.htaccess文件 <IfModule mod_rewrite.c> RewriteEngine On #RewriteBase /smart

我有一个相当复杂的.htaccess文件,其中有许多重写规则,到目前为止,除了我试图重写为一个不是index.php的文件外,所有这些规则都工作得很好

我尝试添加[L]我正在使用xampp轻松地运行它index.php和deleteItem.php都是有效文件。同样值得注意的是,根据我的规则,我不能再直接指向PHP文件了

这是我的.htaccess文件

<IfModule mod_rewrite.c>
  RewriteEngine On

  #RewriteBase /smartsharing/community/
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteRule ^.*?([^/]*)/members$ index.php?action=members&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/members/$ index.php?action=members&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/members/edit$ index.php?action=editMembers&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/members/edit/$ index.php?action=editMembers&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/edit$ index.php?action=editItems&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/edit/$ index.php?action=editItems&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/([^/]*)/purchasehistory$ index.php?action=purchaseHistory&id=$2 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/([^/]*)/purchasehistory/$ index.php?action=purchaseHistory&id=$2 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/([^/]*)/edit$ index.php?action=editItem&id=$2 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/([^/]*)/edit/$ index.php?action=editItem&id=$2 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/([^/]*)/remove$ deleteitem.php?id=$2 [L,QSA]
  RewriteRule ^.*?([^/]*)/items/([^/]*)/remove/$ deleteitem.php?id=$2 [L,QSA]
  RewriteRule ^.*?([^/]*)/edit$ index.php?action=edit&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/edit/$ index.php?action=edit&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]+)$ index.php?action=details&id=$1 [L,QSA]
  RewriteRule ^.*?([^/]*)/$ index.php?action=details&id=$1 [L,QSA]

</IfModule>


重新启动发动机
#重写基础/智能共享/社区/
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^.*([^/]*)/members$index.php?action=members&id=1[L,QSA]
重写规则^.*([^/]*)/members/$index.php?action=members&id=$1[L,QSA]
重写规则^.*([^/]*)/members/edit$index.php?action=editMembers&id=$1[L,QSA]
重写规则^.*([^/]*)/members/edit/$index.php?action=editMembers&id=$1[L,QSA]
重写规则^.*([^/]*)/items/edit$index.php?action=editItems&id=$1[L,QSA]
重写规则^.*([^/]*)/items/edit/$index.php?action=editItems&id=$1[L,QSA]
重写规则^.*([^/]*)/items/([^/]*)/purchasehistory$index.php?action=purchasehistory&id=$2[L,QSA]
重写规则^.*([^/]*)/items/([^/]*)/purchasehistory/$index.php?action=purchasehistory&id=$2[L,QSA]
重写规则^.*([^/]*)/items/([^/]*)/edit$index.php?action=editItem&id=$2[L,QSA]
重写规则^.*([^/]*)/items/([^/]*)/edit/$index.php?action=editItem&id=$2[L,QSA]
重写规则^.*([^/]*)/items/([^/]*)/remove$deleteitem.php?id=$2[L,QSA]
重写规则^.*([^/]*)/items/([^/]*)/remove/$deleteitem.php?id=$2[L,QSA]
重写规则^.*([^/]*)/edit$index.php?action=edit&id=1[L,QSA]
重写规则^.*([^/]*)/edit/$index.php?action=edit&id=$1[L,QSA]
重写规则^.*([^/]+)$index.php?action=details&id=1[L,QSA]
重写规则^.*([^/]*)/$index.php?action=details&id=1[L,QSA]
我的URL类似于

我希望重写的URL是 但事实上,它似乎去了


另外,当发布到它时,它会重定向到而不是
L
是您的规则
RewriteRule^.*([^/]+)$index.php?action=details&id=$1[L,QSA]
导致了问题

规则中的catch-all模式
^.*?([^/]+)$
匹配所有重写的URI,并将它们重写为
/index.php?action=details&id

发生的情况是,当您转到:

/foobar/items/2/remove 
符合以下规则

RewriteRule ^.*?([^/]*)/items/([^/]*)/remove/$ deleteitem.php?id=$2 [L,QSA]
然后,要加载目标url
/deleteitem.php?I'd=124
,服务器再次读取htaccess文件,并匹配以下规则

  RewriteRule ^.*?([^/]+)$ index.php?action=details&id=$1 [L,QSA]
服务器继续读取htaccess文件,直到找不到匹配的规则

要解决此问题,您可以在每个规则中使用
END
标志而不是
L
replace
L
替换为
END
END
标志确保规则仅在当前重写周期中的一个周期内运行,或者在规则上方放置一个RewriteConds,以便它不会重写现有文件或URI

RewriteCond %{REQUEST_FILENAME} !-f

我个人讨厌用
.htaccess
处理复杂的事情。我不太擅长。我将每个请求重定向到
/handle\u request.php
(内部),并且我有一个路由器,它根据URL确定要做什么。并不是说你一定要改用那种方式做事。但我就是这么做的
.htaccess
让我抓狂,谢谢你对发生的事情做出解释,你的解决方案成功了。