Re: [PHP] Creating User Friendly URLS [SOLVED]

2006-08-19 Thread Dave M G

PHP List,

Thank you to everyone who helped out.

I'm happy to report that the issue is solved, mainly with the help of my 
local LUG. I am getting nice friendly URLs, so mod_rewrite seems to be 
working.


The solution was almost entirely to do with getting Apache working. Once 
I had the URLs correctly pointing to my index.php file, then 
manipulating $_SERVER['REQUEST_URI'] was a snap.


The trickiest part for me was that on my own Apache server, mod_rewrite 
was not enabled.


In any case, for my own reference as well as others, although the path 
to the answer was a little stumbly, here are the steps that I think 
ultimately lead to getting everything to work. This is entirely to do 
with setting up Apache to handle friendly URLS, but hopefully will be of 
use to PHP developers.


1. # sudo a2enmod rewrite

2. Confirm that the rewrite.load file is in /etc/apache2/mods-enabled

Currently I have the following files in that directory:
cgi.load  php5.conf  php5.load  rewrite.load

3.  # sudo gedit /etc/apache2/sites-available/default

Find where it says:
   Directory /var/www/
   Options Indexes FollowSymLinks MultiViews
   AllowOverride None
   Order allow,deny
   allow from all

And change AllowOverride None to AllowOverride all. (I noticed that 
None was in upper case, and all was lowercase. Don't know if case is 
important, but this is the way that it worked for me).


Some sites said to edit /etc/apache2/sites-enabled/000-default, or 
sometimes default-000, but they are just symlinks to 
/etc/apache2/sites-available/default (at least in my case).


4. #  sudo gedit /etc/apache2/httpd.conf

Add the following lines:
IfModule mod_rewrite.c
RewriteEngine On
/IfModule

No other editing of httpd.conf was necessary, despite some sites that 
said to use LoadModule.
It should be noted, though, that even though mod-rewrite is working, it 
isn't listed when I run /usr/sbin/apache2 -l. I don't know if that's 
odd behaviour or not, just that it seemed like it was supposed to be 
listed there.

5. Reload the apache modules and restart Apache.

# sudo /etc/init.d/apache2 force-reload
# sudo /etc/init.d/apache2 restart

6. Create an .htaccess file (if there isn't one already) in the 
directory where one wants to create user friendly URLS, and add the 
following:


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php

These rules say that if the file or directory named in the URL is real, 
then go there. Otherwise, go to the index file for processing. At least 
that's what it seems to do. I didn't write it, so I can't assure anyone 
of the correctness of the syntax.


It should be noted, though, that even though mod-rewrite is working, it 
isn't listed when I run /usr/sbin/apache2 -l. I don't know if that's 
odd behaviour or not, just that it seemed like it was supposed to be 
listed there.


If anyone can see problems in the above, or if I've misunderstood some 
part, please let me know.


Thanks to the PHP list for their ever-present help and support.

--
Dave M G

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



Re: [PHP] Creating User Friendly URLS

2006-08-18 Thread Richard Lynch
As a general rule, if you want to see everything useful that is
available to you in your script:

http://php.net/phpinfo

In particular, this will show you the PATH_INFO if it's there, and the
REQUEST_URI if that's there, and...

If neither of those are available, I don't think you'll be able to do
what you want...

It could just be a server configuration issue.

PHP doesn't really decide what to put in $_SERVER.

Your web server puts a bunch of stuff in the environment SERVER
variable, and PHP just passes the buck on to you to do something
useful with it.

Or so I understand it.

On Thu, August 17, 2006 9:43 am, 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-generalm=113597988027012w=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_titleMy 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.

 --
 Dave M G

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




-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Creating User Friendly URLS

2006-08-17 Thread Ray Hauge
On Thursday 17 August 2006 09:43, 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-generalm=113597988027012w=2

 And there is this helpful tutorial:
 http://agachi.name/weblog/archives/2005/01/30/rewriting-dynamic-urls-into-f
riendly-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_titleMy 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.

 --
 Dave M G

Richard has a good article related to this.  Mostly it's about how to force a 
download with a correct filename, but the last part of the article should get 
you pointed in the right direction if you don't want to use mod_rewrite with 
apache.

http://richardlynch.blogspot.com/

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

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



Re: [PHP] Creating User Friendly URLS

2006-08-17 Thread tedd

At 11:43 PM +0900 8/17/06, 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


The ? doesn't cut it for SE's.


I thought I could do this by simply making my link into:
a href=index.php/my_web_page_titleMy Web Page Title/a

And then stripping out the index.php, and using the remainder  for 
both the URL and the database lookup.


Why not just place all your pages inside folders with the names you 
want and then link to the folders?


For example:

a href=mysite.com/my_web_page_titleMy Web Page Title/a

Where my_web_page_title is the name of a folder that contain an 
index.php that produces the page.


tedd

ps: This isn't a php thing, but rather basic html -- unless I'm not 
understanding what you want.


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Creating User Friendly URLS

2006-08-17 Thread Jochem Maas
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-generalm=113597988027012w=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_titleMy 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



RE: [PHP] Creating User Friendly URLS

2006-08-17 Thread Chris W. Parker
tedd mailto:[EMAIL PROTECTED]
on Thursday, August 17, 2006 8:29 AM said:

 And then stripping out the index.php, and using the remainder  for
 both the URL and the database lookup.
 
 Why not just place all your pages inside folders with the names you
 want and then link to the folders?

Because he said database lookup and that means there are no files to
be put into any folders.



Chris.

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