Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 URL路径需要与文件夹路径不同_Php_Url_Redirect - Fatal编程技术网

PHP URL路径需要与文件夹路径不同

PHP URL路径需要与文件夹路径不同,php,url,redirect,Php,Url,Redirect,使用php有没有一种方法可以走这条路 Path: /abc/def/files/websitedomain/from/this/folder/(mynewpages.php location) 把它重定向到这里 Path: /abc/def/files/www/com/(index.php location) 所以我的结果是 website.com/mynewpages 这是我目前唯一的选择。我正在工作的网站是一次非常有趣的经历 编辑:提供的任何解决方案都不能解决我的问题。然而,你们都让我

使用php有没有一种方法可以走这条路

Path: /abc/def/files/websitedomain/from/this/folder/(mynewpages.php location)
把它重定向到这里

Path: /abc/def/files/www/com/(index.php location)
所以我的结果是

website.com/mynewpages
这是我目前唯一的选择。我正在工作的网站是一次非常有趣的经历

编辑:提供的任何解决方案都不能解决我的问题。然而,你们都让我思考。我能够通过PHP访问.htaccess文件

<?php
    $myfile = fopen(".htaccess", "w") or die("Unable to open file!");
    $txt = " copied text + Hello World ";
    fwrite($myfile, $txt);
    fclose($myfile);
?>


成功了。现在我只需要用最好的方法将路径需求写入.htaccess

要在DocumentRoot之外重定向,需要使用mod_rewrite或等效工具。通过PHP includes这样做是不安全的,HTTP重定向(位置头)也不起作用

如果您使用的是Apache,它看起来会像这样(但问题还不够清楚,无法给出具体细节):


DocumentRoot“/abc/def/files/websitedomain”
... 
重新启动发动机
重写规则“^/abc/def/files/websitedomain/from/this/folder/(.*)$”/abc/def/files/www/com/$1”

如果只需要重定向
标题('LOCATION:yourLocationHere'),请使用.htaccess进行重定向;死亡我想使用.htaccess。如前所述,这是目前我唯一的选择。我试图保持积极的态度,不去侮辱开发商。:)您在mynewpages.php中尝试过@PHPglue的建议吗?另一件可能有用的事情(从未使用过)是页面HTML中的元重定向标记。@CMiller它抛出404错误。我至少在努力了解更多。你能举个例子吗?我的php知识真的在接受测试。@Straughold
mod_rewrite
是Apache服务器的一部分,与php无关。啊,这就是我的想法。我误读了你的信息:)。唯一的其他可能性是AJAX或JSON,但我对这两者都没有任何经验,不知道这是否有可能。
<VirtualHost 80>
    DocumentRoot "/abc/def/files/websitedomain"
    ... 
    <Directory "/abc/def/files/websitedomain/from/this/folder">
        RewriteEngine On
        RewriteRule "^/abc/def/files/websitedomain/from/this/folder/(.*)$" "/abc/def/files/www/com/$1"
    </Directory>
</VirtualHost>