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