Using user/SEO-friendly variables in the URL

Discussion in 'WordPress' started by Submerged, Feb 20, 2012.

  1. #1
    Hey, I'm running into a bit of a bind here. I have a page that functions as a dictionary of terms, with the main page linking to the letters A-Z (to show words that begin with each letter). If possible, I'd like the URLs to look as such:

    mysite.com/dictionary/ (main index)
    mysite.com/dictionary/a/
    mysite.com/dictionary/b/
    (and so on).

    However, I'd like to avoid making 26 pages for this purpose (especially when there might be multiple such indexes), so I was hoping that the main page (/dictionary/) could actually send a variable in the URL such that "/dictionary/a/" would actually load the "/dictionary/" page but with "a" as a PHP variable.

    Other solutions would be alright, if that wasn't possible, but I need it to be SEO friendly :).

    Thanks so much for the help!
    - Submerged
     
    Submerged, Feb 20, 2012 IP
  2. thedark

    thedark Well-Known Member

    Messages:
    1,346
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    168
    Digital Goods:
    1
    #2
    Yes, you can do that trough .htaccess file.

    Just make the .htaccess rule that when he see /directory/a/ to translate it into /directory/?term=a
     
    thedark, Feb 21, 2012 IP
  3. Submerged

    Submerged Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thanks for the reply, thedark :).

    I managed to get WP set up to take a variable ('myvar') through the URL, so I need Apache to translate:

    /review/reference/vocabulary/by-alphabet/(a letter here)/
    into:
    /review/reference/vocabulary/by-alphabet/?myvar=(the letter here)

    Then my WP will take it from there. I tried this code, but it doesn't seem to work:

    RewriteRule ^/review/reference/vocabulary/by-alphabet/([a-z])/?$ /review/reference/vocabulary/by-alphabet/?myvar=$1 [NC,L]

    I'm quite inexperienced at Apache, any help would be great :).

    Thanks!
     
    Submerged, Feb 21, 2012 IP
  4. ReputationLinks

    ReputationLinks Banned

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This can be done with a easy edit to the .htaccess, google it for more detailed information
     
    ReputationLinks, Feb 21, 2012 IP
  5. Submerged

    Submerged Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    I've been Googling it for an hour or two, I can't seem to get it to work. I've tried these:

    RewriteRule ^/review/reference/vocabulary/by-alphabet/([a-z])/?$ /review/reference/vocabulary/by-alphabet/?myvar=$1 [NC,L]
    RewriteRule ^review/reference/vocabulary/by-alphabet/([a-z]+)/ review/reference/vocabulary/by-alphabet/?myvar=$1 [NC]

    I've read multiple sites, but I'm at loss here. I've never used Apache. Could someone who knows Apache better just look at those? I'm assuming it's just a small typo of some kind or another :).

    Thanks!
     
    Last edited: Feb 21, 2012
    Submerged, Feb 21, 2012 IP