Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
Apache htaccess重写场景_Apache_.htaccess_Mod Rewrite_Apache2 - Fatal编程技术网

Apache htaccess重写场景

Apache htaccess重写场景,apache,.htaccess,mod-rewrite,apache2,Apache,.htaccess,Mod Rewrite,Apache2,我有一个场景,其中我有两个文件,一个是index.php,另一个是index.htm 如何设置重写条件/规则,以便在服务器上的子目录中存在index.htm时,将请求传递到此文件。如果文件不存在,请将请求传递到/index.php?这取决于您的子目录结构,但一种解决方案是只使用index.php,然后在index.php前面编写一些php来检查是否存在另一个文件: if(file_exists("subfolder/index.htm")) exit(file_get_contents("su

我有一个场景,其中我有两个文件,一个是index.php,另一个是index.htm


如何设置重写条件/规则,以便在服务器上的子目录中存在index.htm时,将请求传递到此文件。如果文件不存在,请将请求传递到/index.php?

这取决于您的子目录结构,但一种解决方案是只使用index.php,然后在index.php前面编写一些php来检查是否存在另一个文件:

 if(file_exists("subfolder/index.htm")) exit(file_get_contents("subfolder/index.htm"));
否则,请检查RewriteCond的标志


这取决于您的子目录结构,但一种解决方案是只使用index.php,然后在index.php的前面编写一些php来检查是否存在另一个文件:

 if(file_exists("subfolder/index.htm")) exit(file_get_contents("subfolder/index.htm"));
否则,请检查RewriteCond的标志


无需重写,使用绝对路径:

DirectoryIndex index.htm /index.php

无需重写,与绝对路径一起使用:

DirectoryIndex index.htm /index.php