Web Hosting Talk







View Full Version : mod_rewrite for dynamic content


wombat
09-22-2001, 08:45 PM
hi,

I want to configure Apache so that a request to any URL in the domain is served by a single PHP script file.

In my naivety I had thought that placing the following lines in .htaccess might achieve this.

RewriteEngine On
RewriteRule /(.*) /index.php


Any thoughts on whether this is sound or have I got hold of the wrong end of the stick entirely???

wombat

Jm4n
09-22-2001, 10:34 PM
Try this:

RewriteEngine On
RewriteBase /
RewriteRule !^index\.php$ /index.php
What you are probably getting is an infinite loop situation. The above will rewrite any URL except for "index.php", avoiding any sort of loop.

I strongly suggest the Apache documentation (http://www.basiclinuxhost.com/docs/Apache-1.3.20/mod/mod_rewrite.html) on this. mod_rewrite is extremely useful, but is also a loaded gun...

freakysid
09-23-2001, 04:16 AM
Can you have a RewriteRule without it being preceded by RewriteCond (s)? I hadn't thought of that.

I would suggest using

RewriteRule (.*) /index.php [L]

Where the [L] flag makes that Rewrite the last one (stops any recursion).

If you did want a condition that catches everything then just match the HTTP_HOST against a pattern of "any character any number of times":

RewriteCond %{HTTP_HOST} (.*)