开发者

redirect and index.php to automatically instance php classes

I would like to create an apache redirect of all .php requests in a specific directory to index.php. In index php I would like to include the file and create an instance of the class.

for example:

mySite.com/directory/classname.php

would be re-directed to mySite.com/directory/index.php

index.php would automatically include_once classname.php

and create instance of classname if the file exists.

I don't want to lose get or post values. I only want .php files redirected

Here is what I have figured out so far, based on understanding of manual & others questions

in .htaccess

## turn on re-write engine
RewriteEngine on 

## base url
RewriteBase / 

## ignore files??
## RewriteCond  %{REQUEST_FILENAME} !-f 

## ignore directories
RewriteCond  %{REQUEST_FILENAME} !-d 

## not index.php
RewriteCond %{REQUEST_FILENAME} !^index.php [NC] 

## if file does not exist then ignore
RewriteRule  ^(.*)$ index.php?param=$1 [QSA开发者_高级运维,L] 

in index.php

$path = $_SERVER["SCRIPT_NAME"];
$path = basename($path, ".php"); 

include_once $path;
$path = new $path;


Try:

RewriteRule \.(php)$ index.php [L,NC]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜