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
.htaccess重写为index.php无限循环_Php_.htaccess_Rewrite_Infinite Loop - Fatal编程技术网

.htaccess重写为index.php无限循环

.htaccess重写为index.php无限循环,php,.htaccess,rewrite,infinite-loop,Php,.htaccess,Rewrite,Infinite Loop,我正在使用.htaccess和php构建一个干净的url系统。 其主要思想是将所有内容重写为index.php,并将url拆分为以/分隔的段。 它可以工作,但当我把它上传到web服务器时,我得到一个无限循环错误 我的.htaccess文件是: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php [L] 如果我理解正确,问题

我正在使用.htaccess和php构建一个干净的url系统。 其主要思想是将所有内容重写为index.php,并将url拆分为以/分隔的段。 它可以工作,但当我把它上传到web服务器时,我得到一个无限循环错误

我的.htaccess文件是:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
如果我理解正确,问题是它会将index.php重定向到自身,但不应该这样做,因为我有index.php文件可以处理所有事情并重写cond%{REQUEST_FILENAME}-这应该可以防止重写

您能帮我完成这个.htaccess吗?我希望它能将所有内容重写为index.php,并尽可能可移植,这样我就可以在:

www.mysite.com www.myothersite.com

甚至 www.mysite.com/new/

我还想将类似www.mysite.com/articles/2的内容重定向到index.php以及www.mysite.com/articles/it/2,甚至是www.mysite.com/articles/it/search/searchterm

以下代码取自使用您试图实现的干净URL方法的.htaccess

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
在本例中,它将干净的URL作为q querystring参数附加。因此,您的脚本可以基于$\u GET['q']检测要交付的内容

这是另一种方法,这是来自


这一个专门查找index.php请求,并在执行重定向之前过滤掉它们。

第二个Wordpress不起作用-再次给我无限循环-显然我做错了什么。然而,Drupal的方法没有循环错误。非常感谢。但我很好奇——这个错误是从哪里来的???很难说。也许您服务器上的另一个脚本正在创建重定向?如果我的原始答案是您问题的解决方案,请将其标记为已接受。花点时间学习如何做到这一点。谢谢
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]