The Web Journal aka Weblog or blog of Jere Matlock
top left corner

quotes | stories | poetry | contact | links

Follow Me!jere matlock subscribe button

top right corner


You've found the blog of Jere Matlock, a web designer and writer. This journal is mostly about writing, web design and getting sites to the top of the search engines (SEO is my business). It is also full of opinions and observations about pretty much everything. If these things are not of interest to you, feel free to go now. Go on, shoo!

Still here? If you have something to say, post a comment or send me an email.

By the way, if you feel like taking offense at something posted on this site, go right ahead, it won't bother me a bit. Kingsley Amis has a nice quote about that, in which I take solace and some pride when the flames arrive:

"If you can't annoy somebody, there's little point in writing."

| Decrease font size for Post - Using .htaccess to make search engine-friendly URLs – “There is no spoon” - Search Engine Optimization - JMBlog | Reset to normal font size for Post - Search Engine Optimization - JMBlog - Using .htaccess to make search engine-friendly URLs – “There is no spoon” | Increase font size for Post - Using .htaccess to make search engine-friendly URLs – “There is no spoon” |

Using .htaccess to make search engine-friendly URLs – “There is no spoon”

User Jan wrote me with the following query about optimizing database driven websites.


Hi there,

I have a question about search engine friendly sites in regard to your article here about SEO of Database-driven Websites. I’m trying to make a website search engine friendly, using descriptive urls. Currently every link to a subpage looks like this: www.dom.ain/?visit=cat

So I only have 1 index file that provides information the user wants. Is there any way to improve this without creating a new php for every page on the site?

I thought about creating a *.htm that will route to the corresponding php url.

E.g. company.htm file routes to /?visit=comp

But I gathered that search engines don’t like links that are opened via Java Script.

Thx for any help, it would be greatly aprechiated.

Kind Regards, Jan


I replied:

When we have a website that uses variables in the domain names, we usually
use a system called Mod Rewrite on a Linux/Apache/mySQL/PHP (LAMP) server
to make more user-friendly URLs. This doesn’t work the same a Windows IIS
server, but works well on a LAMP server. Most websites nowadays are on LAMP
servers.

It works like this:

In the .htaccess file put these lines for each of the pages of the site.
(Contact a web programmer for a quote on doing this if it is beyond your
technical skills — it should be fairly fast and cheap to get done.)

—-
RewriteEngine On
RewriteRule ^airport.php /community.php?unit=airport.php&language=english [L]

—–
You only need to tell it “RewriteEngine On” once. For every page you want to rewrite like this, you add another line.

So when someone goes to airport.php, what they actually get is the community.php page, with all its variables. What Google “sees” is airport.php. What a visitor “sees” in his browser address bar is airport.php.

What’s actually displaying to both Google and your visitor is

community.php?unit=airport.php&language=english

This allows you to have a shorter URL that is more search engine friendly.

Here’s a better example:

RewriteRule ^big-green-widgets.php /product-display.php?productid=widgets&productstyle=blue&productsize=big[L]

There IS no page named big-green-widgets.php on the server. (Like Neo learns in The Matrix movie, “There is no spoon.”)

The server sees a request for the page “big-green-widgets.php” and because of this line in the .htaccess file, the server goes and gets the info it
needs to create the page on-the-fly.

Also, don’t use JavaScript for your links. In your navigation menus, link to the names of the pages you set up in the .htacess file, like “big-green-widgets.php”. Even if that actually mod rewrites over to www.dom.ain/?visit=cat1324, it doesn’t matter. As far as Google and your visitors are concerned, you have a page called big-green-widgets.php.

Mod rewrite is a wonderful tool for anyone trying to optimize a site that is built using only a single page with variables, or using a long string of variables and a database.

Make sense?

Best,

Jeré Matlock

http://www.wordsinarow.com

Website Design & Marketing / SEO


bookmark Using .htaccess to make search engine friendly URLs   There is no spoon

9 Responses to “Using .htaccess to make search engine-friendly URLs – “There is no spoon””

  1. Jere Matlock Says:

    Wow thanks a lot for your reply, not used to getting feedback this fast, and such excellent one too.

    This is pretty much exactly what I was looking for. I guess any further information, for example on dynamic generation of the .htaccess files
    should be available via google.

    Thanks again,

    -Jan

  2. Jim Gaudet Says:

    Thanks for the info, but I have a different question more database related. I would like to have the url like this;

    domain.com/products/category/product-title

    category and product-title with be tables in the database. How can I get it to search the database for the proper category and product?

    How could I get the .htaccess file to forward the variables to the PHP page,which can search for the category and product-title, then generate the page?

    Thanks in advance,

    Jim

  3. Jere Matlock Says:

    If you want to have your website using page names something like this:

    http://www.hubcaps.com/dodge/66-valiant-hubcaps

    that’s fairly easy to set up using a RewriteRule in .htaccess

    RewriteEngine On
    RewriteRule ^dodge/66-valiant.php /display.php?category=dodge&year=66&model=valiant [L]

  4. Mark Says:

    This is great. Thank you.

    It obviously allows people to get routed to the right part of your database but how does a search engine know what to look for? Does it spider the .htaccess file?

  5. Jere Matlock Says:

    No – Google never sees the .htaccess file (it’s inaccessible through normal browsing).

    Instead, when Google requests the page, in much the same fashion as a person browsing the page would request it, the server creates it “on the fly” and gives it to Google based on the action of Google requesting the page. It’s fast and it works. This is how to show elegant, search-engine-friendly URLs while having the actual content come from a database by using question marks, product ids, category ids, and so on. In practice, it works great!

  6. abbas Says:

    hi
    i have any dynamic page like this in my site:
    http://mirsoft.net/detail.php?siteid=433

    how can i change to this : http://mirsoft.net/detail-433.html by .htaccess file.

    thanks.

  7. Jere Matlock Says:

    Hi, Abbas -

    Test this code in your .htaccess file, to see if it works:

    RewriteEngine On
    RewriteRule ^detail-433.htm /detail.php?siteid=433 [L]

    —————-

    Here are some tutorials on using .htaccess that you may find useful:

    http://softexpert.wordpress.com/2007/10/15/learn-htaccess-in-10-minutes/

    http://www.thejackol.com/htaccess-cheatsheet/

    http://www.javascriptkit.com/howto/htaccess.shtml

    Good luck!

    Best,

    Jere Matlock

  8. Jim Butterfield Says:

    Hi Jere.

    I must be missing something. The page (http://www.jmblog.com/2009/11/15/using-htaccess-to-make-search-engine-friendly-urls-there-is-no-spoon/) contains no actual Blog post but only 7 replies. I’d really like to see what you wrote in the first place but I can’t find it. Maybe it’s just my old eyes, but . . . ??? Can you help?

    Thanks
    Jim

  9. Admin Says:

    Thanks for pointing it out – broken by a blog plugin malfunctioning. I’ve repaired the problem.

Leave a Reply

bottom left corner bottom line bottom right corner