Support » Fixing WordPress » Using ModRewrite

Viewing 3 replies - 1 through 3 (of 3 total)
  • Mark (podz)


    Support Maven

    There are few mod_rewrite specialists here, very few.
    Have you tried #apache on ? They many be able to point you to some good sources as it’s their area of interest.


    The Apache Docs would be better than the codex for this.

    There will be loads of examples on the net too, I reckon. Just google for RewriteRule or mod_rewrite.



    Just had a bit more of a look at this. To do something like the second of your requests, you’d need a .htaccess inside the “album” directory containing something like this (it might not be totally correct but it works ;)).

    RewriteEngine On
    RewriteBase /album
    RewriteRule ^([^/]+)/([^/]+)/?$ index.php?pp-album=$1&pp_cat=$2

    This would redirect anything in the form of http://www.yourdomain.tld/album/ducks/geese/ to /album/index.php?pp-album=ducks&pp_cat=geese.

    Note that the [^/] (read: anything but a /) are there as it will match them otherwise – and you probably want /album/ducks/geese/ganders/ to give an error rather than try and redirect to pp-album=ducks/geese&pp_cat=ganders.

    You are going to have to know bits of regex to do this, but it’s not *that* tricky.

    So, to do the “picture.jpg” you would want a RewriteRule like:

    RewriteRule ^([^/]+)/([^/]+\.jpg)$ index.php?pp-album=$1&picture=$2 [L]

    this as the first rule. (the [L] stops the next rule being processed (which would mess things up a tad if it was processed))

    Obviously you want different types of filenames and so it’s probably better to forward anything with a “.” in last part of the path to the album script as an image (rather than a category):

    RewriteRule ^([^/]+)/([^/]+\.[^/]+)$ index.php?pp-album=$1&picture=$2 [L]

    You can probably work out the album bit too.

    None of this is particularly beautiful (nor is it totally correct) — I tend to just hack around with stuff like that until it works. It might be a start for you to have a go exploring what you can do, however.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using ModRewrite’ is closed to new replies.