.htaccess: turn simple dynamic URL into static

Discussion in 'Apache' started by fel64, Mar 22, 2007.

  1. #1
    Hey,
    I've got a seemingly simple problem, but it's not working for a reason I can't fathom.

    I'd basically like to turn

    /fable-2-gallery/categoryname/imagename into /?page_id=14&imgcat=categoryname&imgname=imagename

    but I'm struggling with making that work.

    I'm also running wordpress, which may complicate things. This is what's in my .htaccess file:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^fable\-2\-gallery/([a-z]+)$ fable\-2\-gallery/$1/ [R]
    RewriteRule ^fable\-2\-gallery/([a-z]+)/$ \?page_id=14\&imgcat=$1 [L]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    
    Options All -Indexes
    Code (markup):
    My intention with the first rewrite rule is to simply add a trailing slash to the image category and force a redirect, but unfortunately that's not working.
    The second line should make it dynamic for the PHP to kick in, but again, no luck.

    Can you help me with this, please?
     
    fel64, Mar 22, 2007 IP
  2. jumpenjuhosaphat

    jumpenjuhosaphat Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    jumpenjuhosaphat, Mar 22, 2007 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #3
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^fable-2-gallery/([^.]+)/([^.]+)/([^.]+)\.html$ index.php?page_id=$1&imgcat=$2&imgname=$3 [L]

    /index.php?page_id=WWWWW&imgcat=XXXXXXX&imgname=YYYYYY
    to
    /fable-2-gallery/WWWWW/XXXXXX/YYYYYY
     
    Nintendo, Mar 22, 2007 IP
  4. fel64

    fel64 Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks, but it doesn't work unfortunately. All I get is a 404 whenever anything other than a number is entered after /fable-2-gallery/. (Number after page name is how Wordpress directs to different pages in an article.)

    By the way, page_id is unchaging as it represents fable-2-gallery to Wordpress, so I've only got two parameters.
     
    fel64, Mar 23, 2007 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    Run over to the WordPress message boards on their site. They are crummy when it comes to being friendly with mod_rewrite.
     
    Nintendo, Mar 23, 2007 IP