Re: Using mod_rewrite and PHP

From: Date: Thu, 27 Feb 2003 08:29:06 +0000
Subject: Re: Using mod_rewrite and PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-137366@lists.php.net to get a copy of this message
At the advice of a friendly php-general reader, I tried the following: RewriteEngine on Options +FollowSymlinks RewriteBase /issues/ RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+)([/]?)$ $1/ [R] RewriteRule ^([0-9]/[a-z]/[a-z0-9])([/]?) /index.php?year=$1\&month=$2\&article=$3 And here's my /issues/index.php: <?php print_r($_GET); ?> Requesting http://localhost/issues/2003/feb/issue/ gives a 404 file not found (the logfile shows that it's looking for an un-rewritten URI). Requesting http://localhost/issues/ displays "Array ( )" as expected. Strangely, going to http://localhost/issues redirects me to the hostname (which I have set to 'asdf', causing my browser to end up at http://www.asdf.com). I guess I should have said this earlier, but I'm testing on Win32/PHP 4.3.1/Apache 1.3.27, and have verified the problem on a FreeBSD platform as well. Anyway, thanks for any more pointers, -Dan "Dan Phiffer" <dan@phiffer.com> wrote in message news:20030227073324.44389.qmail@pb1.pair.com... > 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 > >

« previous php.general (#137366) next »