I've been tasked with modifying an existing Wordpress site with URL rewriting. Problem is I've never done this before. I know these rules should go in a .htaccess file in root with something like this in it:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
# END WordPress

However, I have no clue as to how I should specify the rules and conditions for rewriting. I've tried to read up on the mod_rewrite guide, but my somewhat lacking technical abilities limits my comprehension.

Here are the URLs that need rewriting and the desired results:

Generic blog post URL
= www.example.com/blog/custom-post-title/

Specific pages
= www.example.com/about/

= www.example.com/bloggers/

= www.example.com/results/

Generic blogger profile
= www.example.com/blogger/author-name/

Any help with this would be greatly appreciated. Thanks in advance!


You are reverse thinking: you rewrite input URL to match your filesystem.

So you want to rewrite www.example.com/blog/custom-post-title/ to www.example.com/?p=X

For all your pages, go from specific to generic.

RewriteRule ^results/$ /?page_id=10 [L]
RewriteRule ^bloggers/$ /?page_id=4 [L]
RewriteRule ^about/$ /?page_id=2 [L]
#Blogger names
RewriteRule ^bloggers/(.+)$ /?author=$1 [L] #is there really no s to blogger here??
#Other articles
RewriteRule ^(.+)$ /?$1 [L]

I have a little doubt on the last rule, since you don't use filename for redirection (rewrite on /) it may make a new request to index.php?<thequerystring> so we would have to exclude index.php from the last rewrite to avoid infinite loops :

RewriteRule ^index.php$ - [L]

Can be added in front of all others.

  • Thank you! An example such as this was exactly what I wanted. I'll try to wrap my head around it and implement...
    – o01
    Apr 19 '11 at 12:58

Wordpress should be able to do this for you in the permalinks section of the settings.

Failing that, if it can not write directly to your .htaccess file it should give you something to copy and paste.

The only issue I can see is the use of "blogger" instead of author. That you may need to correct, if you see it as important enough.

More Info

  • So if I specify /author/ instead of /bloggers/ I should be ok? I think I can allow that...
    – o01
    Apr 19 '11 at 11:02
  • Have a play and see what you can come up with. It's a really flexible system. All but the author part of your question is really easy, and so might the author bit be, I just haven't done it!
    – Mild Fuzz
    Apr 19 '11 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.