简体   繁体   中英

How do I make this mod_rewrite scheme work with PHP as CGI/FCGI?

Here's the contents of .htaccess:

Options -Indexes
RewriteEngine On
RewriteBase "/"

# Disallow direct access to PHP files.
RewriteRule ^(.*)\.php$ $1 [F,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?<!common/dispatch\.php/)(.*)?$ common/dispatch.php/$1 [NS,L]

Essentially I have all my pages (PHP files) arranged as they would be for direct access without mod_rewrite but I also have dispatch.php in a directory called common , through to which I want all requests to be directed so that I can do some processing before the page script is executed.

It's basically the same idea as used by most frameworks, except I want the page hierarchy to be at the top level and the dispatch script to be kept out of the way with some other bits and pieces in its own subdirectory.

This script works fine on my development machine (which is running PHP as mod_php ), but on the production machine it produces an error saying "No input file specified." if running under FCGI. Under normal CGI it works for the most part but if, for example, I go to /foo/bar (with trailing slash missing) and /foo/bar is a directory in the docroot, it sends me to /foo/bar/?/foo/bar . The rest of the script works fine but I don't really want my URIs getting mangled like this, and ideally I'd like to be able to use FCGI as well.

A potential fix for the problem with FCGI seems to be to put the matched $1 in the query string (ie after a ? ), but this causes all sorts of other odd behaviour that I haven't been able to fix. Is there a straightforward way of fixing this?

仅在php中使用auto_prepend_file指令会不会更容易?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM