Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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 .htaccess返回500,但在重新安排规则时得到修复_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache .htaccess返回500,但在重新安排规则时得到修复

Apache .htaccess返回500,但在重新安排规则时得到修复,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,在.htaccess文件中发生了一些奇怪的事情 不起作用的文件 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*?)/([a-z0-9_-]+)$ $1/post?id=$2 [L,QSA] RewriteRule ^(.*?)/edit/([a-z0-9_-]+)$ $1/editpost.php?id

在.htaccess文件中发生了一些奇怪的事情

不起作用的文件

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*?)/([a-z0-9_-]+)$ $1/post?id=$2 [L,QSA]
RewriteRule ^(.*?)/edit/([a-z0-9_-]+)$ $1/editpost.php?id=$2 [L,QSA]

#RewriteRule ^users/(\d+)*$ ./profile.php?id=$1
但这是有效的

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*?)/edit/([a-z0-9_-]+)$ $1/editpost.php?id=$2 [L,QSA]
RewriteRule ^(.*?)/([a-z0-9_-]+)$ $1/post?id=$2 [L,QSA]

#RewriteRule ^users/(\d+)*$ ./profile.php?id=$1
我只是重新安排了重写规则,它解决了这个问题。有人能解释为什么会这样吗?我被困在这两个多小时了


我是新的网址重写,所以请详细解释。而[L,QSA]实际上是做什么的呢?

RewriteCond
只适用于最近的
RewriteRule
。因此,在第一个示例中,它仅适用于此规则:

RewriteRule ^(.*?)/([a-z0-9_-]+)$ $1/post?id=$2 [L,QSA]
两个底部的
RewriteRule
在没有任何
RewriteCond
的情况下执行,并导致无限循环

您可以将规则设置为:

RewriteEngine On
RewriteBase /

# skip all files and directories from rules below    
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^(.*?)/edit/([\w-]+)/?$ $1/editpost.php?id=$2 [L,QSA]

RewriteRule ^users/(\d+)/?$ profile.php?id=$1 [L,QSA]

RewriteRule ^(.*?)/([\w-]+)/?$ $1/post?id=$2 [L,QSA]

对于你的第二个问题,看。不,新代码给了我404错误。但是无限循环现在没有发生。404即使我使用了旧的丑陋的url。等我从你的代码中删除1行后,一切都正常了…你能解释一下原因吗?选项-MultiViewsok。选项
MultiViews
(请参阅)由
Apache的内容协商模块
使用,该模块在
mod_rewrite
之前运行,并使Apache服务器匹配文件扩展名。因此,如果
/file
是URL,那么Apache将提供
/file.html
。最有可能的是您的目标
post?id=…
执行
post.php?id=…