-1

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 Answers1

-2

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>
Nicholas Shanks
  • 10,623
  • 4
  • 56
  • 80
  • Can you provide an example? My php knowledge is really getting tested atm. – Straughnhold Dec 23 '17 at 00:49
  • @Straughnhold `mod_rewrite` is part of the Apache server, nothing to do with PHP. – Barmar Dec 23 '17 at 01:02
  • Ah that is what I thought. I misread your message :). The only other possibilties are with AJAX or JSON, but I don't have any experience with either of those to know if that is even a possibility. – Straughnhold Dec 23 '17 at 01:25