duanqun9618 2017-12-23 00:24
浏览 139

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

Using php is there a way to take this path

Path: /abc/def/files/websitedomain/from/this/folder/(mynewpages.php location)

and redirect it in here

Path: /abc/def/files/www/com/(index.php location)

so my result is

website.com/mynewpages

This is my only option available at the moment. The site I am working has been a very interesting experience.

EDIT: None of the solutions provided solved my problem. However, you all got me thinking. I was able to .htaccess file via PHP

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

That worked. Now I just need the best way to write my path needs into .htaccess.

  • 写回答

1条回答 默认 最新

  • douchuntang2827 2017-12-23 00:35
    关注

    To redirect outside of the DocumentRoot you need to use mod_rewrite or equivalent. It's not safe to do this via PHP includes, and a HTTP redirect (Location header) won't work.

    If you're using Apache, it'll look something like this (but the question isn't clear enough to give specifics):

    <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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀