cheesedude — 2010-08-15T13:06:13-04:00 — #1
I am currently using the following rewrite provided by dklynn. It works great.
RewriteRule ^/?([a-zA-Z0-9_-]+)$ /rewrite.php?param1=$1 [L]
RewriteRule ^/?([a-zA-Z0-9_-]+)(/([a-zA-Z0-9_-]+))$ rewrite.php?param1=$1¶m2=$3 [L]
RewriteRule ^/?([a-zA-Z0-9_-]+)(/([a-zA-Z0-9_-]+))?(/([a-zA-Z0-9_-]+))?$ rewrite.php?param1=$1¶m2=$3¶m3=$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:
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?
jphilipson — 2010-08-16T01:00:25-04:00 — #2
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.
cheesedude — 2010-08-16T11:15:14-04:00 — #3
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.
dklynn — 2010-08-15T23:20:46-04:00 — #4
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.
dklynn — 2010-08-16T18:26:01-04:00 — #5