Rewrite relative path

New to mod_rewrite? This is a good place to start.

Rewrite relative path

Postby BMN » Sun Jul 05, 2009 3:05 pm

I want these:
sharedacct/public_html/sample/home.htm
sharedacct/public_html/sample/pic.jpg
sharedacct/public_html/sample/sub/home.htm
sharedacct/public_html/sample/sub/pic.png


redirected to here:
sharedacct/non_public/code/sample.php?relpath=home.htm
sharedacct/non_public/code/sample.php?relpath=pic.jpg
sharedacct/non_public/code/sample.php?relpath=sub/home.htm
sharedacct/non_public/code/sample.php?relpath=sub/pic.png


I cannot get it to work when trying to pass "." or "/". Also, the request may include several "/"s and "."s - (eg. /sample/sub.2/sub3/photo.pic.jpg)

The Apache docs confuse me and I could not find the same here in the forums.

Hopefully someone can help me out. Thanks.
BMN
 
Posts: 39
Joined: Wed Jul 05, 2006 2:15 am

Postby richardk » Mon Jul 06, 2009 12:13 pm

Mod_rewrite can't rewrite outside the current document root. So you can try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^sample/(.+)$ /sharedacct/non_public/code/sample.php?relpath=$1 [QSA,L]

and some different paths to sample.php but it probably won't work.

You will probably need to create a new PHP file in public_html/, eg. sample.php with the following in it
Code: Select all
<?php

include('../code/sample.php');

and use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^sample/(.+)$ /sample.php?relpath=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 115 guests

cron