Using mod_rewrite and PHP
| From: | Dan Phiffer | Date: | Thu, 27 Feb 2003 07:33:23 +0000 |
| Subject: | Using mod_rewrite and PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137365@lists.php.net to get a copy of this message | ||
So I'm trying to implement a URL system like so:
http://domain.org/issues/2003/feb/article-name/
such that http://domain.org/issues/index.php will
display the requested
page. I've read a little about this
(http://www.alistapart.com/stories/succeed/) and have gotten it to work for
the most part, but there's one problem I'd like to resolve.
Here's how I've got it set up:
- I put a .htaccess file in http://domain.org/issues like so:
RewriteEngine on
RewriteRule !\.(gif|jpg|png|css|js)$ index.php
- /issues/index.php contains code to respond to REQUEST_URI and serve
content
appropriately.
- Requests to /issues/ should serve an index sort of page, which works fine.
However, if a request is made to /issues (no trailing slash), the browser is
sent an Error 400 Bad Request.
I tried the following after looking at the URL Rewriting Guide
(http://httpd.apache.org/docs/misc/rewriteguide.html):
RewriteEngine on
RewriteBase /issues/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
Unfortunately, with this in place the browser displays a 302 Found message
with a link to the same problematic URL (/issues). I'm still pretty new to
mod_rewrite, so please bear with me if I'm doing something obviously wrong
here.
Thanks,
-Dan