PDA

View Full Version : mod rewrite based on first letter


Level Level
07-07-2009, 03:31 PM
Hi all,

I need some help with the following:

I'm building some sort of a glossary in WordPress. It's working fine, I'd just like to rewrite the URLs of the glossary posts to the appropriate glossary page.

for example the post http://myurl.com/category-glossary/example1
should redirect to the page http://myurl.com/glossary/?snap=E

http://myurl.com/category-glossary/anotherexample
should go to http://myurl.com/glossary/?snap=A

do basically i would like to redirect based on the first letter of a glossary post. Is there anyone who could point me in the right direction?

Thanks!

ninnypants
07-08-2009, 05:44 AM
try putting this in your .htaccess

RewriteRule (.*glossary/)([^/])/? $1?snap=$2 [L, R=301]


I'm using something similar to this in one of my projects

Level Level
07-08-2009, 10:19 AM
Thanks for your reply ninnypants,

it's not working quite yet, I get a 500 internal server error. I have also made a mistake in my initial request..

the original URL is fairly similar to the resulting URL, it should be:

http://myurl.com/glossary/example1/ should redirect to the page http://myurl.com/glossary/?snap=E

and http://myurl.com/glossary/anotherexample/ should go to http://myurl.com/glossary/?snap=A

Could you please take a look at it again? Thanks a million!

ninnypants
07-09-2009, 05:26 AM
The 500 error is probably from something else in your .htaccess file. Also it's impossible to tell what the first letter is and capitalize it unless you create a RewriteRule for every letter in the alphabet.

Level Level
07-09-2009, 08:28 AM
ok, thanks for replying, i'll check my .htaccess