为什么.htaccess中来自toro php路由器的配置不起作用?

问题描述:

the Toro docs show:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

but i tryed many times and different ways, but, doesn't work... After a lot of searching i found this (source):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php?$1 [L]

Just need to change in RewriteRule ^(.*)$ /index.php/$1 [L] the / to ? , to get this RewriteRule ^(.*)$ /index.php?$1 [L]

Someone know why the original doesn't work, or have a different aproach for this?

MORE INFO Host: php5.4 fastcgi, shared host, company Dreamhost. Just accept SCRIPT_NAME instead of PATH_INFO

the Toro code that handle it is:

$path_info = '/';
        if (!empty($_SERVER['PATH_INFO'])) {
            $path_info = $_SERVER['PATH_INFO'];
        }
        else if (!empty($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO'] !== '/index.php') {
            $path_info = $_SERVER['ORIG_PATH_INFO'];
        }
        else {
            if (!empty($_SERVER['REQUEST_URI'])) {
         $path_info = (strpos($_SERVER['REQUEST_URI'], '?') > 0) ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI'];
                }
        }

Toro docs 显示: p>

  RewriteEngine on 
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{REQUEST_FILENAME}!-d 
RewriteCond $ 1!^(index  \ .php)
RewriteRule ^(。*)$ /index.php/$1 [L] 
  code>  pre> 
 
 

但我尝试了很多次和不同的方式,但是,没有 工作......经过大量的搜索,我发现了这一点(来源):

  RewriteEngine on 
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{REQUEST_FILENAME}!-d 
RewriteCond $ 1!^(index \ .php)
RewriteRule ^(。*  )$ /index.php?$1 [L] 
  code>  pre> 
 
 

只需要更改 RewriteRule ^(。*)$ /index.php/$1 [ L code> / code> strong>到 ? code> strong>,以获取此 RewriteRule ^(。* )$ /index.php?$1 [L] code> p>

有人知道为什么原件不起作用,或者有一个di 为此提出了不同的方法吗? p>

更多信息 strong> 主持人:php5.4 fastcgi,共享主机,公司Dreamhost。 只接受SCRIPT_NAME而不是PATH_INFO p>

处理它的Toro代码是: p>

  $ path_info ='/'; 
 if(!empty($ _ SERVER ['PATH_INFO']]  )){
 $ path_info = $ _SERVER ['PATH_INFO']; 
} 
 if if(!empty($ _ SERVER ['ORIG_PATH_INFO'])&&  $ _SERVER ['ORIG_PATH_INFO']!=='/ index.php'){
 $ path_info = $ _SERVER ['ORIG_PATH_INFO']; 
} 
 else {
 if(!empty($ _ SERVER ['REQUEST_URI  '])){
 $ path_info =(strpos($ _ SERVER ['REQUEST_URI'],'?')> 0)?  strstr($ _ SERVER ['REQUEST_URI'],'?',true):$ _SERVER ['REQUEST_URI']; 
} 
} 
  code>  pre> 
  div>

You probably are running on a server that doesn't support the PATH_INFO style of cgi. This is where the script itself is /index.php and the "PATH_INFO" is the pathname that comes after it. Take a look at the AcceptPathInfo documentation:

This directive controls whether requests that contain trailing pathname information that follows an actual filename (or non-existent file in an existing directory) will be accepted or rejected. The trailing pathname information can be made available to scripts in the PATH_INFO environment variable.

For example, assume the location /test/ points to a directory that contains only the single file here.html. Then requests for /test/here.html/more and /test/nothere.html/more both collect /more as PATH_INFO.

The primary purpose of the AcceptPathInfo directive is to allow you to override the handler's choice of accepting or rejecting PATH_INFO. This override is required, for example, when you use a filter, such as INCLUDES, to generate content based on PATH_INFO. The core handler would usually reject the request, so you can use the following configuration to enable such a script:

<Files "mypaths.shtml">
Options +Includes
SetOutputFilter INCLUDES
AcceptPathInfo On
</Files> 

So you could try turning AcceptPathInfo to "On" and see if that helps.

This is all about mapping URLs to paths to scripts that generate response.

Apache gets HTTP request, which contains a URL, specifically the path and query string part of it. Mod_rewrite rewrites the URL using rules from the server configuration (multiple files: apache2.conf, httpd.conf, virtual host configs, .htaccess, …). Then Apache splits it in the first question mark and interprets the path part as a filesystem path (with DocumentRoot prepended). If the file does not exist, 404 Not Found response is usually generated. If it is an image or a HTML document, it is sent as is. If it is a script, it is executed and somehow gets query string and other info from the request.

I cannot be very specific, because Apache is very modular and configurable. Especially script execution is quite a complicated topic. The general part of Apache's work is request parsing → URL to filesystem path mapping → response generation.

URLs visible to clients can contain no question marks at all and still a script can be executed and be given some extra info from the URL. One way to do this is URL rewriting using mod_rewrite and .htaccess, where / is rewritten to ?. As Jon Lin already wrote, AcceptPathInfo is another option. I am not sure if any of them is clearly better or worse for your needs. When used on a large server, performance is likely to be an issue, but that's not your case.