Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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]
</IfModule>
# 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/?p=X
= www.example.com/blog/custom-post-title/

Specific pages
www.example.com/?page_id=2
= www.example.com/about/

www.example.com/?page_id=4
= www.example.com/bloggers/

www.example.com/?page_id=10
= www.example.com/results/

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

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

share|improve this question

migrated from stackoverflow.com Apr 20 '11 at 10:47

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 2 down vote accepted

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.

#Specifics
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.

share|improve this answer
    
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

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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