mod_rewrite help

Discussion in 'Apache' started by nfin1ty, Dec 30, 2006.

  1. #1
    So i am not very good with mod_rewrite but am curious and desiring to learn.. so for fun i wanted to remove the .php from my scripts.. so i was wondering how to do so.

    ive tried a few things and gotten the whole extension removed (such that /script.php?query_str turns into /script/query_str) but i'd like to make it look like this:
    /script?query_str (simply removing the .php and not adding the / to appear as a directory)

    how do i do this? i modified my rewrite rule to do this but it doesn't work.. if i try /script?query_str in the addy bar, it automatically puts a / in between script and ? which isn't right (so it looks like /script/?query_str)

    does anyone know how to make it do just /script?query_str??


    thx for the help.. its prolly somethin simple i'm just not accustomed to the htaccess stuff yet..
     
    nfin1ty, Dec 30, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Post an example of the dynamic URL and how you want it.

    script?query_str

    is NOT the best way. If you're going to change it, you want it 100% static. aka /script/query_str or /script/query_str.html
     
    Nintendo, Dec 30, 2006 IP
  3. nfin1ty

    nfin1ty Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok so basically right now i just use get_env to pull the query string as a whole.. so script.php?query_string would yield to a specified variable which will be used to pull correct content the string "query_string"
    i'm keeping this exactly the same, but would like to use mod_rewrite to simply remove the .php after script, such that http//domain.nm/script?query_string would be the exact same thing.. i just dont know how to construct the part of the rule which accepts script?query_string and rewrites to script.php?query_string.
    i hope that clarifies.. i have it partially working (doing a simple http//domain.nm/script/query_string) but when i try to construct the pattern i just cannot get anything to work.. i always end up getting a script/?query_string when i try to go with script?query_string..

    EDIT: just to clarify, this is not meant to be used widely on the site, i'd just like to know if there was a way how to do this. i do know how to make it completely pseudo-static.. i just would like to play around and learn something different!
     
    nfin1ty, Dec 30, 2006 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^script?([^.]+)$ script.php?$1 [L]

    BUT, I don't think it'll work cause ? isn't mod_rewrite friendly.

    script/query_str

    is probably the only way you can have it, and

    script?query_str is hardly any better than the original, SEO wise.
     
    Nintendo, Dec 30, 2006 IP