的.htaccess重写到index.php无限循环
我建立使用的.htaccess和PHP一个干净的URL系统。 其主要思想是重写一切index.php文件和网址分裂由/分隔段。 它的工作原理,但是当我把它上传到Web服务器,我得到一个无限循环的错误。
I am building a clean url system using .htaccess and php. The main idea is to rewrite everything to index.php and to split the url to segments separated by /. It works but when I upload it to web server I get an infinite loop error.
我的.htaccess文件是:
My .htaccess file is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
如果我得到的东西正确的 - 问题是,它重定向的index.php本身,但它不应该,因为我有一个处理index.php文件的一切,的RewriteCond%{} REQUEST_FILENAME -f!
应prevent的改写。
If I get things correctly - the problem is that it redirects index.php to itself but it shouldn't because I have index.php file that handles everything and RewriteCond %{REQUEST_FILENAME} !-f
which should prevent that rewrite.
能否请你帮我这的.htaccess - 我希望它改写一切的index.php是便携,因为它可以,这样我就可以使用它:
Could you please help me with this .htaccess - I want it to rewrite everything to index.php and to be as portable as it can be, so I can use it in:
www.mysite.com www.myothersite.com
www.mysite.com www.myothersite.com
甚至 www.mysite.com/new /
or even www.mysite.com/new/
我也想重定向像www.mysite.com/articles/2到index.php,以及www.mysite.com/articles/it/2甚至www.mysite.com/articles/it/search /搜索关键词
I also want to redirect something like www.mysite.com/articles/2 to index.php as well as www.mysite.com/articles/it/2 or even www.mysite.com/articles/it/search/searchterm
下面是从 Drupal的的拍摄code的.htaccess它使用干净的URL方法,你要实现的目标。
Here's code taken from Drupal's .htaccess which uses the "clean urls" approach you are trying to achieve.
# 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查询参数。所以,那么你的脚本可以检测什么内容,提供基于 $ _ GET ['Q']
。
In this case, it appends the clean URL as the "q" querystring parameter. So then your script can detect what content to deliver based on $_GET['q']
.
和这里的另一种方法,这种情况一方面源自字preSS 。
And here's another approach, this one from Wordpress.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
这一家专门寻找请求的index.php
和筛选出来做重定向之前。
This one specifically looks for requests to index.php
and filters them out before doing the redirection.