tags:

views:

95

answers:

3

i'm hosting a website through a hosting company [1] on a linux/apache server. until now i serve the different content through one script with parameters. an example url is

www.mydomain.com/pages.php?date=1-10-2008

now i want to change the scheme the url is composed of to something which looks completely like a path url. eg.:

www.mydomain.com/pages/date/2008/20/1

for this i need to switch off the normal mapping of url paths to directory folders in apache: all requests to all paths should go to one central script (pages.php), which than analyzes the path component of the url.

how do i tweak apache for this? i hope some .htaccess rules could the trick.

[1] btw, the hosting company is godaddy.com.

A: 

Rather than parse the url in your script, you should be able to handle the specific example above with Apache's ModRewrite module.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

You can use these in the .htaccess file, assuming your host allows this.

Andy Hume
+1  A: 

You are looking for mod_rewrite. Example htaccess file:

RewriteEngine On
RewriteBase /
RewriteRule ^pages/([^/]*)/(.*)$ pages.php?$1=$2
phihag
+2  A: 

Something like:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ! -f
RewriteCond %{REQUEST_FILENAME} ! -d
RewriteRule . pages.php

should rewrite every request for a file or directory that doesn't exist to pages.php. This will allow you to keep static files (images, stylesheets, etc) in the same document root.

(Shamelessly stolen from WordPress :) )

mwalling
I should read the docs before checking the community wiki box :(
mwalling