RewriteRule, just one thing missing!!

Discussion in 'Apache' started by Christopher Turner, Feb 2, 2011.

  1. #1
    Ok after much research on the RewriteRule with apache2 I have come to the end of my tether and would like to ask someone that maybe already has this working, or to take a look at my example and see why its missing this 1 last very important rule to my application.

    Rewrite brief, I am trying to achieve the following;

    Externally
    INPUT=    http://localhost/path/to/index.php
    REDIRECT= http://localhost/path/to/
    
    INPUT=    http://localhost/path/to/index.php/path/info/here/
    REDIRECT= http://localhost/path/to/path/info/here/
    Code (markup):
    Internally
    INPUT=  http://localhost/path/to/
    OUTPUT= http://localhost/path/to/index.php
    
    INPUT=  http://localhost/path/to/path/info/here/
    OUTPUT= http://localhost/path/to/index.php/path/info/here/
    Code (markup):
    Rewrite Rule
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /path/to/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} ^(.+)index\.php$
    RewriteRule ^(([^/]+/)*)index\.php$ $2%{PATH_INFO} [R=301]
    Code (markup):
    Whats working and whats not.

    Internally the RewriteRule pushes all the requests correctly to the index.php file within the server, the actual issue is the external redirect of the url.

    If the user requests the following page:

    http://localhost/path/to/index.php
    Code (markup):
    It effectively redirects them correctly to

    http://localhost/path/to/
    Code (markup):
    BUT, and a huge annoying BUT when the path info is included with the index.php in the url it redirects the user to the host root with the path info.

    http://localhost/path/to/index.php/path/info/here/
    Code (markup):
    Gets redirected to the following;
    http://localhost/path/info/here/
    Code (markup):
    This is what it should look like;
    http://localhost/path/to/path/info/here/
    Code (markup):
    It seems to be missing out the path to the index.php when redirecting.

    So in all I what it remove any reference to the index.php file and if the index.php file is included within the url, redirect it to the a url without it BUT apache will still know to add it in internally. I personally think that urls look cleaner this way, rather than having index.php?getvar=here&anothervar=here&andonemore=there.

    Now I am a person that likes to know how this works, not just give the RewriteRule please. I have taken alot of time to try and figure it out, but I think the problem is with the regular expression?

    I would just like to know if anyone has achieved this exact RewriteRule, or if any apache gurus know what alterations I need to make.

    Thankyou-please!! :)
     
    Christopher Turner, Feb 2, 2011 IP
  2. moads

    moads Member

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #2
    Get rid of this... "RewriteBase /path/to/"
     
    moads, Feb 3, 2011 IP