by on

Page One

This method of URL rewriting is meant for those running Apache. It is easy to set up because the only server configuration changes to be done are done in the .htaccess file.

First, a look at the URLs and where we are heading with it for this example:

Original > www.yoursite.com/article.php?cat=category&id=23

Re-written > www.yoursite.com/article/category/23/

You can see that the rewritten version appears as if it is working off of your server's directory structure. In actuality, you are simply passing variables to a script with "/"'s in between. Let's do it:

  1.  Save your article.php file (from the frontend files, not the backend!) as a new file called "article". Be sure that this new file has no file extension at all.
  2. Open your .htaccess file or create one if you do not have one already. In this file, add the following:
    <Files article>
    ForceType application/x-httpd-php
    </Files>

    (This is based on using the Apache version of PHP. Your Forcetype may be differnent if PHP is compiled for CGI)
    The word "article" corresponds to whatever you named your article file in Step 1. This code forces Apache to read "article" as a PHP file even though it has no PHP extension.

  3. Save or upload your .htaccess file into the directory containing your front-end PHP files for Miraserver.
  4. Open your "article" file in a text editor. Insert the following into the top of the file:
    $url_array=explode("/",$REQUEST_URI);  //BREAK UP THE URL PATH USING '/' as delimiter
    $cat=$url_array[2]; //Category
    $id=$url_array[3];  //Article ID #
    $p=$url_array[4];  //Page #

    This code parses the URL into an array, using "/" as the delimiter. Then, it access the variables in the array by their element ID's. This code is designed for front-end files in the root directory of your site. If they are located in a sub-directory of your site, you will need to advance the element numbers to coincide.

  5. Save your "article" file. Ensure that there is no php,txt or htm extension on the file. Upload the file to your server into the same location as all of your other Miraserver front-end PHP files.
  6. Test it. The URL is working in this format:
    www.yoursite.com/article/ CATEGORY SHORTNAME / ARTICLE ID #PAGE NUMBER /
    Page Number is optional. If it is not defined, it will default to page one.

The same process can be done on the category pages for Miraserver. Save a new copy of your "index.php" file as "category" with no file extension. Then use $url_array[2] to be the shortname for the category. You do not need an article number or page number. When done successfully, this will result in a URL like:

 www.yoursite.com/category/shortname/

rather than:

www.yoursite.com/index.php?topic=shortname

A successful re-writing hack will also necessitate some code editing in the other templates. You will need to make sure that all references to the old URL version are re-written. This will involve changes in some PHP coding, but mostly in the template themselves (which can be done in any HTML editor).

For technically minded individuals, this is a pretty simple hack. But, if you cannot wrap your head around this, you can contact me at drisley@pcmech.com directly and ask me questions. I will also do the entire hack for you for a small $25 labor charge.


This article is copyrighted.