Pages Navigation Menu
 

Clean URL’s with WordPress

Beautiful WordPress Themes

This tutorial will show you how to setup WordPress to use clean URL’s. Using clean URL’s is one of the first step in Search Engine Optimization (SEO). Besides that, they just look better.

The default WordPress URL structure is: http://www.yoursite.com/?p=123. What does p=123 even mean? Well, I would guess that it is the post id, but what does your reader see? A URL like this will be much better: http://www.yoursite.com/category/title-of-the-post be much better. It will have some meaning to your readers, and more importantly, search engines. The title is one of the most important things a search engine will look at. The better your site places on the SERPs (search engine results page), the more traffic you will drive to your site. Of course this is only one step in SEO, but is a good start.

There is one thing to keep in mind before you change your permalink structure. You will lose inbound links from other sites and search engines. If you have a large amount of traffic from direct addresses or bookmarks, you will not have to worry about this. If you are just starting out (as we are here at www.teamtutorials.com), I would recommend going with clean URL’s from the start. It is really simple to make a custom permalink structure for WordPress.

First, if your .htaccess file is writeable, WordPress is supposed to update it automatically. If not it will give you the code to cut and paste into your .htaccess file. I have had problems letting WordPress edit the .htaccess file in the past (it never seems to update it), so I will edit it manually.

Log on to your WordPress account as the administrator and click on Options and then Permalinks. You should see a page similar to the one below.
Clean URL’s with WordPress

As you can see, the default settings are select. We want to enable custom URL’s so click the option button next to “Custom, specify below”.
Clean URL’s with WordPress

Now we need to define the URL’s. There are many variable that you can use, but I will choose to use the category and postname variables. If you would like to use something else (day, month, year, posted, subcategory, etc.) you may want to see the custom permalinks page on the Official WordPress site. In the “Custom Structure” box, enter the following.
Clean URL’s with WordPress

Now scroll to the bottom and click the “Update Permalink Structure” button.
Clean URL’s with WordPress

Now, if you have a writeable .htaccess file, you can ftp to your site and check to see if .htaccess file was edited. If your .htaccess is not writeable, or WordPress didn’t update it, you will need to enter the following code in the file and upload it to your site.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>

This will tell the server that when it see http://www.yoursite.com/categiory/post-title-here to rewrite it to http://www.yoursite.com/index.php?somevariable , but the user will see the clean URL.

To test it, make a new post or use an existing one. Click the link from your homepage to get to the permalink and look at the URL in the web browser. You should see the clean URL and the page should be displayed properly.
Clean URL’s with WordPress

Here is our ugly default URL versus the clean URL for the same post.
Clean URL’s with WordPress

Vs
Clean URL’s with WordPress

This is an easy way to optimize your site for search engines and be easier on your readers eyes. If you have any questions, just leave a comment, I will answer as quickly as possible.

  • http://AdamDempsey.net Adam Dempsey

    Great tip, thanks :) I’m going to make sure I set this on all my blogs from now on.

  • http://www.tutorials.ge M.W.S.

    Hello, I’m using Georgian language (UTF-8) and it has errors with encoding URL-s. can you help me?

  • Deborah

    This makes sense to me, except what happens if I have named pages, which aren’t necessarily categories?

    I’m new to blogs, just installed WordPress this afternoon, but want to have an “About” and “Contact” pages which are found through the links http://www.mysite.com/about and http://www.mysite.com/contact.

    How does your rewrite method affect how those pages are referenced?

  • http://www.projectcrankwalk.com John Ward

    If a file or folder exists, it is display. Noticed the REQUEST_FILENAME param. There are two of them in the rewrite statement. One !-f for file and one !-d for directory. This tells the web sever that if a file or directory exists, skip the rewrite rule.

  • http://www.projectcrankwalk.com John Ward

    By the way. We have been using this technique on the site for awhile now. We haven’t really had any problems with it. Except (if you guy’s noticed) we used an apostrophe in the title for this post. As you can see in th URL it doesn’t like the apostrophe and it makes the URL look messy. It is kind of funny that the only page on this site with a bad URL is the one about cleaning your URL’s.

  • Deborah

    Thanks John for the quick response! I’m moving along with my WordPress site. Sure helps to have sites like yours with good advice to answer my questions.

  • http://www.gammaleasing.com Luca della Rocca

    it seems that apostrophes in permalink is a wordpress bug, maybe the list of special characters that get sanitized should be updated, look:
    http://trac.wordpress.org/ticket/3843

  • André Felipe

    What if an article has two categories? How will be the URL of this article?

  • Benji Franklin

    Question: How do I change .htaccess and configuration to add the www at the beginning of the URL? It has been eliminated somehow during set-up and now I see I have lost my old page rank which was at the www address. Arghhhh …. In addition to changing the .htaccess and wordpress config would I need to change anything in my template .. think I have some links hardcoded in there without the www which I might have to redo or would they be redirected so long as I change .htaccess?

    Anyway, great site.

    Any help would be great appreciated.

  • http://poker.extrinsec.com/ online poker for money

    @Benji Franklin … I think you have to setup this from your domain registrar. I can tell you for sure it’s not htaccess.

  • http://www.teamtutorials.com John Ward

    yes you can set the prefer domain to yoursite.com or http://www.yoursite.com. This is not a function of the registrar you can do this in .htaccess.

  • http://www.claudiudesign.org/ Web Design Prices

    In addition to changing the .htaccess and wordpress config would I need to change anything in my template .. think I have some links hardcoded in there without the www which I might have to redo or would they be redirected so long as I change .htaccess?

  • darkdragon312

    your information was very helpful. i understand everything until it reaches the step about .htaccess. could you elaberate on the steps after that, please reply to my e-mail.

    A response would be heavily appreciated

  • http://hapier.com hapi

    great tips.i will try later on my new built wp websites.thanks!

  • http://www.projekty-domow.newsiktwo.eu/story.php?title=rim-blackberry-curve-8300-att-cingular-email-pda-phone Luy O.

    Great blog you got here…keep up the good work.

  • Navin

    Hi Pal,

    I implemented the same way as written in the article above for clean URL. On hovering on the post I am getting clean URL. I tried opening the post, it is showing –

    Oops! This page appears to be missing.
    HTTP 404 – File not found.

    Please let me know how to rectify this problem.

  • http://www.pcsinparadise.com Frank

    This information is very helpful for my needs. Thank you very much

  • http://www.speakerpulse.com Saul

    I’m using Drupal and it handles this function out of the box extremely well… HOWEVER. It’s like driving a ferrarri in bumper to bumper traffic and I need to scale back to wordpress in order to save myself from a huge insurance claim.

    I’ll give this a try as soon as I get a second. Thank you!

  • Hank

    4 0 3 error!

    difficult to get the site back to working.

  • JohnS

    Please help :(
    I want to transform this:

    http://site.com/index.php?mod=article&cat=X&article=2
    To
    http://site.com/X/2

    What must i write in .htaccess?!?

    I’ve tried a million things and nothing works… Please help, i must launch my web-site soon and i’m a noob lol, but no one must know that :)
    Thank you.

  • http://www.popsci.com Robert Chen

    So I attempted subscribing to your RSS .xml, and it kicked back a “404” error… Can you tell me if it’s just me or the site?

  • http://microvoltshacks.wordpress.com MicroVOlts Cheats 2011

    I just MicroVolts. Here’s a shooter game oriented around toy soldiers at a secret feud against each other, and when you pick in this war you will be tactile to use some first class cheats, because days. You can try these excellent MicroVolts Cheats simply, just goto http://microvoltshacks.wordpress.com and get the best hacks available.

  • http://seospoon.com scooby

    thanks for the great subject matter, i just stunbled on your site? well done superb information

  • http://www.mvanlaerhoven.nl Marijn

    Thanks for the tip/link that you posted on my own website. I didn’t succeed because I couldn’t find the htaccess file you talk about?

  • http://vision4life.in Mathukutty

    Many Many Thanks. My site is in Drupal 7.9, But I would like to change into WP. I was searching how to create clean urls and found your post. Just tried, and wow, done it. http://vision4life.in/blog/how-to-disable-right-click-functionality-on-desktop

    Sir, Can you help me please? I would like to know any plugin available for migrating/converting my drupal 7.9 site into WP. Basic pace, Book page, Gallery, Youtube videos etc are the contents. Pls help if u can.