Mod_rewrite QUERY_STRING to directory?

Discussion in 'Apache' started by DarkBabylon, Apr 2, 2011.

  1. #1
    So I have a simple mod_rewrite problem:

    I want this:
    mydomain.com/index.php?p=article&id=24sfhjs2378dhs

    to be:
    mydomain.com/article/24sfhjs2378dhs


    Currently I'm using:
    
    # General Stuff
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    
    #Domain removal of www.
    RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?thebabylontimes\.com)$ [NC]  
    RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
    
    #Redirection (which is working btw) for a couple pages
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^home /index.php?p=home [L]
    RewriteRule ^music /index.php?p=music [L]
    RewriteRule ^tech /index.php?p=tech [L]
    
    Code (markup):

    Thanks so much, this is very urgent.
    Cheers,
    --
    Nick.
     
    DarkBabylon, Apr 2, 2011 IP
  2. zacharooni

    zacharooni Well-Known Member

    Messages:
    346
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    120
    #2
    RewriteRule /article/(.*) /index.php?p=article&id=$1 [L]
     
    zacharooni, Apr 3, 2011 IP
  3. DarkBabylon

    DarkBabylon Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?mydomain\.com)$ [NC]  
    RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule /article/(.*) /index.php?p=article&id=$1 [L]
    RewriteRule ^article /index.php?p=article [L]
    
    RewriteRule ^home /index.php?p=home [L]
    RewriteRule ^music /index.php?p=music [L]
    RewriteRule ^tech /index.php?p=tech [L]
    Code (markup):
    Sorry not working yet. Anything you see that would stop the rule?
     
    DarkBabylon, Apr 3, 2011 IP