1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

mod_rewrite check for file existance in parent directory

Discussion in 'Apache' started by Aragorn, Oct 2, 2007.

  1. #1
    I know a little bit of mod_rewrite and have provided help here one or two times. But this is beyond me. Whenever a page is accessed, I want to the check whether the requested file exists in the current directory or the base parent directory. If not I want the request to be rewritten to another file. I got this much
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    Code (markup):
    But I don't know how to check whether the file exists in the parent directory.
    I will give an example. suppose the user request for /test/path_to_file/filename.php, then the request should be rewritten to /index.php if either one of the following files do not exist
    /test/path_to_file/filename.php or
    /path_to_file/filename.php

    Can anyone please tell me how I can do it? Thanks :)
     
    Aragorn, Oct 2, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    That would involve string manipulations in the rewrite conditions which is beyond the capabilities of .htaccess

    It can be done with server side scripting though, and it seems you already are using PHP so it shouldn't be much of a problem :)
     
    krt, Oct 2, 2007 IP
    Aragorn likes this.
  3. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Thanks. That means things are much complicated than I thought :(
     
    Aragorn, Oct 3, 2007 IP