UPDATE: How to Blog has MOVED! Please update your bookmarks and feeds! The new address is :
http://www.emilyrobbins.com/how-to-blog/
and all new posts and post updates will be made there! Comments and trackbacks at this location are now closed -- please visit the new How to Blog site in order to add a comment or a trackback and see updates to existing posts as well as all new posts from this point forward!

« Templates for WordPress - Gemini layout, Trident layout, and The Vesuvius layout now available for download | Main | "Sorry, you need to enable sending referrers, for this feature to work." error when trying to activate plugins in WordPress »

August 25, 2004

How to configure WordPress to create search engine friendly URLs for permalinks

THIS POST HAS BEEN MOVED TO:

http://www.emilyrobbins.com/how-to-blog/how-to-configure-wordpress-to-create-search-engine-friendly-urls-for-permalinks-242.htm

Please update your bookmarks to reflect the new, permanent location of How to Blog.  Comments and trackbacks on this post are now closed.  If you wish to comment on this post, please visit the new site!  Thank you!

-----------------------------------------------------------------------------------------------------------------------

WordPress's default behavior for permalinks is to create a URL that looks something like this:

http://www.yoursite.com/index.php?p=2

where p is the post id.

If you care at all about the search engines indexing your blog, and you should if you want anyone to read it :), you'll want to use a little SEO (search engine optimization) trick by having nice, neat URLs that describe your post.

In my case, I wanted my individual post archives to be in the root of my domain, as search engines like Google devalue a page the deeper it is into the site. I also wanted the link title be the posts name, so that my permalinks will look like this: http://www.yoursite.com/this-is-my-posts-title.htm

To do it:

- log into WordPress, and then click on 'Options'. Next click the sub-category under options entitled "Permalink"

- the page you're on will now describe all the fields you can use to create your permalink. I only cared about the post name so in the edit box just underneath where it says, "Use the template tags above to create a virtual site structure:" I typed the following:

/%postname%.htm

- at this point you should click the button to Update Permalink Structure.

Now you will need to modify your .htaccess file to do some mod-rewriting. Sounds hard, but WordPress makes it easy. First of all, if you don't know what it is, an .htaccess file is simply a text file that can contain instructions for the webserver. If you have an .htaccess file already, then you will need to edit it to add the code that WordPress provides for you (see below). If you don't have an .htaccess file, you'll need to create a text file using any text editor (notepad will do) that simply has the contents (again, see below) that WordPress tells you paste in. Those directions will be specific to the linking structure you choose, but if you go the route I went, then WordPress will have you add the following lines to your .htaccess file:

RewriteEngine On
RewriteBase /
RewriteRule ^category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2 [QSA]
RewriteRule ^category/?(.*) /index.php?category_name=$1 [QSA]
RewriteRule ^author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2 [QSA]
RewriteRule ^author/?(.*) /index.php?author_name=$1 [QSA]
RewriteRule ^([_0-9a-z-]+).htm([0-9]+)?/?$ /index.php?name=$1&page=$2 [QSA]
RewriteRule ^([_0-9a-z-]+).htm/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?name=$1&feed=$2 [QSA]
RewriteRule ^([_0-9a-z-]+).htm/trackback/?$ /wp-trackback.php?name=$1 [QSA]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1 [QSA]
RewriteRule ^comments/feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1&withcomments=1 [QSA]

So now, my first WordPress post on my Tool Reviews Site can be found at http://www.toolreviews.biz/porter-cable-cffn250n-finish-brad-nailer-combo-kit.htm (btw - that post is more of a placeholder while evaluating WordPress than anything else..)

August 25, 2004 in SEO, Weblogs, WordPress | Permalink | Email This Post

Bookmark with del.icio.us, add to Yahoo!MyWeb or Digg This!

Comments

Thank you soooo much for this page! I've spent the past two or so weeks really studying blogware options, as I want to move away from blogger.com. While I'm quite comfortable with handcoding HTML & CSS, validating, and even customizing a few perl scripts, the blog world is new to me, in the hands-on sense. WP seemed to be a great choice, but I despised the no-information-given URLs it creates. Your page perfectly responds to that concern.

Now, if I can just get up the heart to delve into the unknown (to me) world of php and mySQL. Fortunately, my (new) host, Pair Networks, has the required software in place. I'll do some more reading about the basics, so come Labor Day weekend, I can take a huge cup of coffee, and dig in. By then, I *should* have made the final choice between b2evolution and wordpress.

I owe ya one! Thanks again.

pam

Posted by: Pam G. | Aug 26, 2004 10:08:28 PM

Thank you, I tried it on an WP blog I maintain and it works. Just did as you write and put the .htaccess in the document root, which in my case is not the wordpress directory.

If you care you can find it here: www.reister.org. Its my family design and sculpture activity.

Posted by: blau | Oct 10, 2004 5:02:26 AM

One item to note, if you have links to individual posts either in your blog or from other sites, editting the .htaccess may cause those links to be broken if you have editted the permalinks in the past. I would recommended that you add in the additional lines rather than a replacing the file completely. That seemed to work better on my site it in my site.
Mark

Posted by: Mark | Nov 12, 2004 9:53:26 AM

/%postname%.htm

I added the above code in my permalink setting and entered the generated code to an htaccess file.

i added some new posts to the blog since completing the steps above.

the problem is i seem to have blown up my wp blog. what ever link in the post i click -- post title, comment, -- the page isn't found. i can't add comments to posts anymore.

it's a new blog -- my first one.
ne1 know what i must do to fix this problem?

Posted by: Joe | Jan 10, 2005 6:34:54 PM

I wanted to impliment this because I feel it would be much better. It worked fine until I clicked on my categories. I found that my template was thrown into chaos and since I'm a newbie at all this, I didn't know how to fix the problem and had to revert back to the default.

Do you have any idea what went wrong, and how I can fix it?

Posted by: Karen | Jan 19, 2005 4:22:52 AM

Thanks for this way. But when I click any of my post, getting the following error:

Not Found
The requested URL /wp/toyota-expert-says-high-volume-hydrogen-powered-fuel-cell-cars-at-least-25-years-away.htm was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Posted by: ppaul | Jan 22, 2005 2:49:07 AM

I tried this, it works - except for when it is listing all the months - wordpress no longer shows the link (www.example-site.com/archives/10/03) - instead it just shows (www.example-site.com/archives).

How do I fix this?

Posted by: AD | Jan 31, 2005 5:27:37 AM

Thank you!

Posted by: Henrik Rasmussen | Feb 7, 2005 8:12:08 AM

When I click one of the months under Archives I get page not found and this is the url:

http://twowayradiodirectory.com/blog/%postname

The messages do have the correct url with the postname in them.

Anyone know a fix?

Thanks

Posted by: Henrik Rasmussen | Feb 7, 2005 8:25:16 AM

I fixed it by using

/archives/%year%/%monthnum%/%day%/%postname%/

instead of just

/%postname%.htm

Posted by: Henrik Rasmussen | Feb 7, 2005 9:11:57 AM

Not sure what the .htaccess is for (color me duh I'm blushing) but i ended up deleting it to get this to work. The links work fine but when I click on the permalink, it breaks all the graphics (which may explain what the .htaccess is for LOL........

Posted by: cece | Feb 9, 2005 8:19:46 PM

what about other linking fucnctions... my wordpress was linking with index.html?m=22341235 etc, now they are all gone :P

Help please

Posted by: wolfy | Feb 10, 2005 9:31:14 PM

ive followed your blog about the permalinks but now the "pages" ive made dont display in the side bar. how can i fix this?

www.clearwatermed.net

Posted by: Lee | May 15, 2005 8:49:40 AM

sorry the url is www.clearwatermedia.net i think it might be because the pages are now in folders?

Posted by: Lee | May 15, 2005 8:58:28 AM

AWESOME thanks for explaining it so easily, had such a hardtime w/ WordPress' explaination.

Posted by: Nick | Aug 19, 2005 5:25:37 PM

Very nice. Thanks for explaining it, Wordpress is a very interesting blog software.

Posted by: Mustafa | Sep 26, 2005 6:46:20 AM

Thanks so much for the great tip! My blog is about SEO and I'm a newbie at blogging so your information was the best of both worlds for me. I read the other posts on this thread and found a reference that might help some folks out:

http://codex.wordpress.org/Using_Permalinks#Fixing_.28.htaccess.29_Generation_Issues

I hope this helps. Thanks again for the great tip!

Posted by: Mike | Oct 2, 2005 7:53:02 AM

Hi,

Even I had seen many answers, I couldn't find the way to my server to work with friendly URLs.

This is the error I am getting everytime.

500 Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@kakoky.net and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.0.48 Server at www.XXXXXX.net Port 80

Posted by: nando | Oct 4, 2005 5:34:40 PM

Where is the .htaccess file supposed to go when I'm using WorPress thru a DreamHost hostplan? TIA.

Posted by: Billy | Dec 9, 2005 1:17:26 PM

Hi,
I've installed wordpress and used this structure
/archives/%postname%/

and wrote a test post titled - testing Wordpress

The permalink generated is
http://www.mysite.com/blog/archives/testing-wordpress/

but when you click on it an error is generated saying

"The requested URL /blog/archives/testing-wordpress/ was not found on this server."

What could be the problem. Please advise

Gerald

Posted by: Gerald Njuguna | Dec 14, 2005 3:08:32 AM

Thanks for the guide.

I'm using the custom setting and everything seems to work fine including the category option. The only problem seems to be the Title on top. It looks like this:

Site name >> Blog Archives >> Custom Title

Even though I post new articles/news/blogs the word 'Blog Archives' continue to appear on Title of the page. Can this be done away with? I want it to look like this:

Site name >> Custom Title

Thank you in advance!

Posted by: Kurt | Jan 31, 2006 1:40:47 AM

@Kurt - what displays on the title of your page is wholly controlled by what theme you are using for your WordPress blog. You can either change to a different theme that displays the title the way you want, or modify your current theme to customize the title on the category page. Page titles are not affected by permalinks. Hope that helps!

Posted by: Emily from How to Blog | Jan 31, 2006 1:45:07 PM

Thanks for this post - helped me fix a problem with my htaccess file and now permalinks are working!

Posted by: AnotherWin95 | Feb 3, 2006 6:39:46 PM

Worked like a charm - thanks for helping out!

Posted by: Neil Merton | Feb 16, 2006 3:42:37 PM

Terrifying! But worked great. We love your site, thanks for all the help - you rock!

Posted by: dailyModern | Feb 23, 2006 4:18:18 PM

The comments to this entry are closed.

UPDATE: How to Blog has MOVED! Please update your bookmarks and feeds! The new address is :
http://www.emilyrobbins.com/how-to-blog/
and all new posts and post updates will be made there! Comments and trackbacks at this location are now closed -- please visit the new How to Blog site in order to add a comment or a trackback and see updates to existing posts as well as all new posts from this point forward!