Creating nice URLs with PHP and Apache, without mod_rewrite
Results 1 to 2 of 2

Thread: Creating nice URLs with PHP and Apache, without mod_rewrite

  1. #1
    Senior Member
    Join Date
    Jul 2004
    Location
    Oxford, England
    Posts
    1,983

    Creating nice URLs with PHP and Apache, without mod_rewrite

    I notice that a lot of people want to know how to create "pretty" URLs, that are more human readable than

    http://mysite.example.com/something.php?id=12364

    A lot of people use mod_rewrite to achieve this. Although this works, it's a lot of hassle and not always available.

    Here's an alternative method I use:

    1. Create a PHP script which uses PATH_INFO. Path info is the part of the path *after* the PHP script's URL. Example:

    http://mysite.example.com/something.php/123456

    This can be got using $_SERVER['PATH_INFO']

    2. To make things nicer, I use a PHP script whose filename doesn't end in .php. This is pretty straightforward if you're using Apache, because

    Code:
    <Files en>
            ForceType application/x-httpd-php
    </Files>
    in .htaccess causes any file called 'en' to be treated as a PHP script despite its name NOT ending in .php. In fact you could do this for all your PHP scripts. Or you could make a single script which invokes the appropriate function based on its PATH_INFO.

    The URLs on our shop sites can look something like this:

    http://www.worldofhealth.co.uk/en/ke...o-mat-standard

    This is considerably more human-readable than something with a query string in.

    Mark

  2. #2
    Construction zone
    Join Date
    Apr 2004
    Posts
    1,833
    Whoa...oddly enough I'm right now trying to write some stuff that deals with uri processing. Another approach to try out here...

    Thanks...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •