views:

41

answers:

2

I have a script at www.mydomain.com/mydirectory/index.php. I want to map all requests to subdirectories of mydirectories to the script. For instance, www.mydomain.com/mydirectory/mypath/ should be rewritten to www.mydomain.com/mydirectory/index.php/mypath/

How can I accomplish this? Thanks.

A: 

Try this in the .htaccess file in your mydirectory directory:

RewriteEngine on
RewriteCond $0 !^index\.php/
RewriteRule .* index.php/$0 [L]
Gumbo
This cause the server to return an 404 error, which I interpret as that the server is looking for the physical subdirectory but not finding any (cause there are no physical subdirectories).Can it be made such that it does not look for the physical subdirectory but instead effectively make a new HTTP request to the given subdirectory?Thanks.
Anders Feder
@Anders Feder - Make sure that you've [set `AcceptPathInfo`](http://httpd.apache.org/docs/2.0/mod/core.html#acceptpathinfo) correctly as well. `mod_rewrite` is essentially making a new internal request, it's just problematic sometimes (for whatever reason) to create `PATH_INFO` in the process.
Tim Stone
A: 

This will forward all requests to index.php if a requested file or folder doesn't exist:

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

For example, http://www.example.com/category/5/ becomes http://www.example.com/index.php/category/5/

You can parse the path behind index.php using explode() and $HTTP_SERVER_VARS

$url = explode('/', $HTTP_SERVER_VARS['PATH_INFO']);
spidEY
My RewriteRule I've used is > RewriteRule .* index.php/$0 [PT] -- I also had this just below RewriteEngine On > RewriteBase / -- Either way, this should work.
Stephen Perelson