Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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
Php 将任何文件夹中的任何索引页重定向到另一个文件,但仍然能够包含它_Php - Fatal编程技术网

Php 将任何文件夹中的任何索引页重定向到另一个文件,但仍然能够包含它

Php 将任何文件夹中的任何索引页重定向到另一个文件,但仍然能够包含它,php,Php,我需要将以下路径重定向到accessPoint.php,但在accessPoint.php中,我需要包含/需要请求的重定向文件,可以这样做吗 .htaccess位于根/forms/.htaccess中 ./forms/form1/index.php ./forms/form2/index.php ./forms/form3/index.php ./forms/form4/index.php ./forms/form5/index.php 以上内容将重定向到 -/accessPoint.php

我需要将以下路径重定向到
accessPoint.php
,但在
accessPoint.php
中,我需要包含/需要请求的重定向文件,可以这样做吗

.htaccess
位于根
/forms/.htaccess

  • ./forms/form1/index.php
  • ./forms/form2/index.php
  • ./forms/form3/index.php
  • ./forms/form4/index.php
  • ./forms/form5/index.php
以上内容将重定向到 -/accessPoint.php

我现在所拥有的:

RewriteEngine on
RewriteCond %{REQUEST_URI} /*/index.php
RewriteRule ^.*$ /accessPoint.php [R=302,L]
当前的
accessPoint.php
,仅通过尝试包含其中一个文件进行测试,但未显示任何内容:

<?php

    echo 'access point';

    include './forms/form1/index.php';

您所描述的内容是正确的。如图所示,当包含一个php文件时,它不会通过web服务器,而只是读取本地文件系统。我怀疑你的
RewriteCond
不正确。试试这个,例如:

RewriteCond %{REQUEST_URI} "\/index\.php$"
编辑:到问题中的更新。例如,完全处理这种情况的方法是使用绝对路径

<link href="/css/structure.css" rel="stylesheet">

或者,更好的方法是使用php确定要包含的内容:

<?php
$BASE_PATH = '/';
echo "<link href=\"{$BASE_PATH}css/structure.css\" rel=\"stylesheet\">"
?>

?>
您所描述的内容是正确的。如图所示,当包含一个php文件时,它不会通过web服务器,而只是读取本地文件系统。我怀疑你的
RewriteCond
不正确。试试这个,例如:

RewriteCond %{REQUEST_URI} "\/index\.php$"
编辑:到问题中的更新。例如,完全处理这种情况的方法是使用绝对路径

<link href="/css/structure.css" rel="stylesheet">

或者,更好的方法是使用php确定要包含的内容:

<?php
$BASE_PATH = '/';
echo "<link href=\"{$BASE_PATH}css/structure.css\" rel=\"stylesheet\">"
?>

?>

然后会发生什么?包含文件不会使用
.htaccess
毕竟文件似乎不会被包含,但我不知道包含文件不会使用
.htaccess
所以这有助于解决我的问题,谢谢@NicoHaase查看更新后请不要编辑您的问题,使其包含一个完全不同的问题。相反,为此提出一个新问题——包括所有相关信息。在当前的情况下,您可能会感兴趣地看到,您正在使用哪个URL加载页面,而不是加载它的CSS,然后更改样式表链接的生成,然后会发生什么?包含文件不会使用
.htaccess
毕竟文件似乎不会被包含,但我不知道包含文件不会使用
.htaccess
所以这有助于解决我的问题,谢谢@NicoHaase查看更新后请不要编辑您的问题,使其包含一个完全不同的问题。相反,为此提出一个新问题——包括所有相关信息。在当前的情况下,您可能会很感兴趣地看到,您正在使用哪个URL加载页面,而不是加载它的CSS,然后更改样式表链接的生成