Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重定向和index.php以自动实例化php类_Php_Class_Redirect_Instance - Fatal编程技术网

重定向和index.php以自动实例化php类

重定向和index.php以自动实例化php类,php,class,redirect,instance,Php,Class,Redirect,Instance,我想创建一个apache重定向,将特定目录中的所有.php请求重定向到index.php。在索引php中,我希望包含该文件并创建该类的实例 例如: mySite.com/directory/classname.php 将被重新定向到mySite.com/directory/index.php $path = $_SERVER["SCRIPT_NAME"]; $path = basename($path, ".php"); include_once $path; $path = new $pa

我想创建一个apache重定向,将特定目录中的所有.php请求重定向到index.php。在索引php中,我希望包含该文件并创建该类的实例

例如:

mySite.com/directory/classname.php

将被重新定向到mySite.com/directory/index.php

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

include_once $path;
$path = new $path;
index.php将自动包含_once classname.php

如果文件存在,则创建classname的实例

我不想丢失get或post值。 我只想重定向.php文件

根据对手册和其他问题的理解,以下是我迄今为止得出的结论

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] 
在index.php中

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

include_once $path;
$path = new $path;
尝试:


请告诉我您已采取适当措施避免包含任意文件。仍在处理详细信息。can$\u服务器[脚本\u名称];妥协?