On Wed, 16 Apr 2008 16:54:58 +0200, k3pp0 <upthekhyber@gmail.comwrote:
Quote:
Hello.
>
I'm trying to make use of "pretty URLs" with Apache's rewrite module.
>
Here's what I want:
>
http://foo.bar/index.php?download
>
should be replaced with
>
http://foo.bar/download
>
My .htaccess looks like that:
>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
>
In the index.php I look at $_SERVER['REQUEST_URI'] and act
accordingly:
>
$requestedURI = empty($_SERVER['REQUEST_URI']) ? false :
$_SERVER['REQUEST_URI'];
>
switch($requestedURI) {
case "/download":
include "download.php";
break;
default:
// do something
break;
>
}
>
This works if I go to
http://foo.bar/download - it shows index.php
with the included download.php file. But if I go to
http://foo.bar/download/
(with a slash at the end of the URL) it doesn't do anything (default
case of switch($requestedURI)), because "/download" != "/download/".
>
To solve this I could just make two cases: case "/download" and case
"/
download/", but I don't really like this solution, if there's a
better
one, please tell me.
>
Let's take it I use the method with the two cases ("/download" and "/
download/"), there's another problem:
In the index.php I've included a stylesheet: "<link rel="stylesheet"
type="text/css" href="main.css" />". As you can see, I use a relative
link to the css file. So if I call
http://foo.bar/download, it loads
the css file from
http://foo.bar/main.css, but if I enter
http://foo.bar/download/
(with the slash) it can't find the css file, because it tries to
locate it at
http://foo.bar/download/main.css, but of course, there
is
no main.css, /download/ is not even a directory... How do I fix this?
Several propabilities. The first:
http://example.com/download is NOT the
same as
http://example.com/download/ for obvious reasons, so why not just
fail with a Not Found header, as you would with 'example/com/nonsense'?
Obviously that's not what you want, so you might:
1)
a) use $url = trim($url,'/'); or
b) $paths = explode('/',$url); (for more levels in the future?)
2) When playing with rewrites, you want all links from the root, so a
simple '<link .. href="/main.css"solves the second problem.
--
Rik Wasmus