SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Posts
    1,834
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    Rewrite to file above public_html?

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

    Code:
    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?

    Thanks.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2005
    Posts
    1,834
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    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.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    CD,

    No problem!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •