Need mod rewrite rule

Discussion in 'Site & Server Administration' started by amanamission, Oct 28, 2007.

  1. #1
    Hi, I just need help writing the correct mod_rewrite rule to transform my script-generated URL's to the actual pages I wish to use:

    http://www.domain.com/index.php?a=page&id=word

    to

    http://www.domain.com/word.htm

    best would be rule which could deal with either .htm or .html, as I actually need to transform pages to both, but I'll settle for the first.

    Here's a rule that isn't doing anything. Can anyone tell me what might be wrong with this?

    RewriteEngine On
    RewriteBase /
    Options +FollowSymlinks
    RewriteRule ^([^/]*)\.html$/index.php?a=page&id=$1 [L]
     
    amanamission, Oct 28, 2007 IP
  2. inworx

    inworx Peon

    Messages:
    4,860
    Likes Received:
    201
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Belongs to Apache.
     
    inworx, Oct 29, 2007 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #3
    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteRule ^([^.]+)\.html$ index.php?a=page&id=$1 [L]

    Only if you want search engines seeing duplicate content should you use both .htm and .html.
     
    Nintendo, Oct 29, 2007 IP
  4. amanamission

    amanamission Notable Member

    Messages:
    1,936
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    210
    #4
    What I mean is, I have some pages (early ones) that are .htm, started using .html later, so some pages would .htm. I also have to figure out how transform for directory URLs.


    Thanks for the rule...I'll see if it does the trick.

    It did not: it gave me:
    The requested URL /karmaalliancelightinstitute.com/w0712/d37/s14/b0286d91/www/karmaalliancelightinstitute.com/index.php was not found on this server.

    It's really strange...all the rules I try do the opposite of what I want-if they work at all.
     
    amanamission, Oct 30, 2007 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    It acts like

    karmaalliancelightinstitute.com/index.php doesn't exist.
     
    Nintendo, Oct 30, 2007 IP
  6. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    whats your full base dir to the www folder ? some hosts have a very wacky modrewrite implementation knowing your base dir will help.
     
    ndreamer, Oct 30, 2007 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #7
    er, yah!! That might help!!!!

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^.]+)\.html$ index.php?a=page&id=$1 [L]
     
    Nintendo, Oct 30, 2007 IP
  8. amanamission

    amanamission Notable Member

    Messages:
    1,936
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    210
    #8
    Thanks Nintendo-the rule works with RewriteBase /

    Must always remember that when doing .htaccess.

    Now the problem is that this works too well-rewrites all .html addies.

    Maybe I'll use all those pages with the script and make new pages with wordpress permalinks to get rid of the extension.

    I also need one-to-one rule that will rewrite specific subdirectories (i.e. domain.com/title/ as I have some pages like that that also need to change.

    Is is a bad idea to write one-to-one RewriteRules for each page and have 30-40 rules in my .htaccess?
    In that case, I guess I just replace the parenthesis with the page title.
    I'll return to the thread with any problems I run into.
     
    amanamission, Nov 1, 2007 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #9
    You would have to add a fake directory or change the extension for it to not mess up real pages.
     
    Nintendo, Nov 1, 2007 IP