Rewrite to file above public_html?

I am currently using the following rewrite provided by dklynn. It works great.


RewriteEngine On

RewriteRule ^/?([a-zA-Z0-9_-]+)$ /rewrite.php?param1=$1 [L]
RewriteRule ^/?([a-zA-Z0-9_-]+)(/([a-zA-Z0-9_-]+))$ rewrite.php?param1=$1&param2=$3 [L]
RewriteRule ^/?([a-zA-Z0-9_-]+)(/([a-zA-Z0-9_-]+))?(/([a-zA-Z0-9_-]+))?$ rewrite.php?param1=$1&param2=$3&param3=$5 [L]

rewrite.php functions as the controller (directs requests to various files depending on the resource requested) for anything that requires rewriting. However, I want to make a change. Instead of using rewrite.php as a controller, I want to use another file above public_html.

My server directory structure is like this:

/home/username/public_html/addon_domain

The current htaccess file resides in the /addon_domain folder and rewrites to /addon_domain/rewrite.php.

I keep my code above public_html. I would like to redirect to /home/username/scripts/controller.php

Is it possible to rewrite to a file above public_html and how would I go about doing that? I’ve looked for an answer for over an hour now and cannot seem to get anything to work. Everything is relative to the document root where htaccess resides and I cannot find a way to go above it. Maybe I am missing something simple? :confused:

Thanks.

Agree with what was said above - you can rewrite to a URL you couldn’t load via HTTP in the first place. And good idea with rewriting to a file that include()'s it.

OK, dklynn. I understand now. I thought that Apache could rewrite to any file in the user account and not just in the publicly available folders below public_html. I could just rewrite to a PHP file under public_html and include in something above public_html. As a matter of fact, that is the work-around I used while waiting for an answer to my question.

Thanks for your help. :slight_smile:

CD,

First, please remove the / before rewrite.php in the first RewriteRule.

Second, can you access the scripts/controller.php file via http? Of course not! Therefore, you can’t send a redirect outside the webspace. What you can do, if required, is to redirect to a file INSIDE your webspace which include()s the …/…/scripts/controller.php file.

Regards,

DK

CD,

No problem!

Regards,

DK