Re: Creating User Friendly URLS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



1. assign a 'page' a 'friendly url' - this is probably done in your CMS

2. write a routine that will generate a 'friendly url' for a given 'page' in your cms;
   this allows you to stick the 'friendly urls' in a menu for instance.

3. write a routine for taking any given url and trying to match it against
   a 'page' in your CMS (let it return the page data and/or id if successful)

4. setup your webserver to redirect non-existent urls to a handler script that
   will use the routine from 3 to try and find the correct page. sticking to apache
   this can be done in at least 2 ways:

	a, use mod_rewrite - to which I can only say RTFM ;-)
	b, use the ErrorDocument directive, which would look something like:
	
		ErrorDocument 404 /myhandler.php

5. write a 'handler script' as mentioned in 4. if your are using "ErrorDocument"
you will need to output a 'Status: 200' header if your handler finds a page matching the
requested url.

6.  do var_dump($_REQUEST, $_SERVER) in your 'handler script' to find out exactly
what info you have to play with - you should be able to find everything you need.



Dave M G wrote:
> PHP List,
> 
> My goal is to create user and search engine friendly URLs like:
> mysite.com/my_web_page_title
> 
> Instead of:
> mysite.com/index.php?pageID=1
> 
> I asked about this before:
> http://marc.theaimsgroup.com/?l=php-general&m=113597988027012&w=2
> 
> And there is this helpful tutorial:
> http://agachi.name/weblog/archives/2005/01/30/rewriting-dynamic-urls-into-friendly-urls.htm
> 
> 
> Both of which refer to a variable called $_SERVER['PATH_INFO'].
> 
> But, in the php.net manual, in the predefined variables page,
> 'PATH_INFO' is only obliquely referenced in the $_SERVER variable
> description, under the 'PATH_TRANSLATED' element.
> 
> When I've tried echoing out the contents of $_SERVER['PATH_INFO'], I get
> nothing.
> 
> I'm trying to set it so that pages are named according to their title in
> my MySQL database. So my script will pull "my_web_page_title" out of the
> URL, match that against the database, and then display the appropriate
> contents.
> 
> I thought I could do this by simply making my link into:
> <a href="index.php/my_web_page_title">My Web Page Title</a>
> 
> And then stripping out the "index.php", and using the remainder  for
> both the URL and the database lookup.
> 
> But, while I'm sure there are more steps than that, I'm halted initially
> because I'm not sure where in the $_SERVER array my URL is being stored.
> 
> Any advice on how to proceed here would be greatly appreciated. Thank you.
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux