mod_rewrite to overcome relative urls

Discussion in 'Apache' started by jhodgson4, Jun 3, 2013.

  1. #1
    I've taken over a site that caters for client access. They all access there own folder, and in the folder the files have an include with a relative path as below.
    /core - contains all the actual files
    /client/file.php -
    <? include "../core/file.php";?>
    but with the growing number of clients I want to go a level deeper and separate them better...
    /uk/client/file.php -
    <? include "../../core/file.php";?>
    This is fine but when the files are included, they too have there own relative includes and this is where it breaks.
    There are so many files I can't easily go through them to change all the include paths so I would like to maybe do a rewrite to fake the path?
    I've tried this...
    RewriteRule^uk/$ /
    But that doesn't work.
    Any help would be greatly appreciated
     
    jhodgson4, Jun 3, 2013 IP
  2. Zarko Dimitrov

    Zarko Dimitrov Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    I don't know if you can do this with rewrites. The best way would be to have the full path like
    include /home/yoursite/public_html/core/file.php
    If you are running the sites on apache and have SSH access simply login and do this :
    perl -pi -e 's/find/replace/g' *.php
    or
    find . -name '*.php' |xargs perl -pi -e 's/find/replace/g'
    Assuming you have .php files (you need to escape the input like 's/find/replace/g' '/s/include ..\/core\/file.php etc);
     
    Zarko Dimitrov, Jun 6, 2013 IP
  3. jhodgson4

    jhodgson4 Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Wow you've opened my eyes to a whole new way of thinking!

    Thank you so much for the reply, it did the trick and will help enormously in the future.

    Joe
     
    jhodgson4, Jun 9, 2013 IP