views:

307

answers:

3

Hi guys, I need a set of fresh eyes on this. I'm having a tough time spotting the problem.

In folder X I have an .htaccess file with the following two lines in it:

RewriteEngine on
RewriteRule ^([A-Za-z0-9\.-]+)/?$ item-display.php?bibid=$1 [NC,L]

My interpretation is that anything in that directory will then be redirected to the item-display page. The problem is that on the item-display page, echoing out the value of bibid outputs 'display-item'. So somehow I'm redirecting from: http://localhost/test/cat/item/14056a to: http://localhost/test/cat/item/item-display.php?bibid=item-display

Any ideas?

Cheers

+1  A: 

Try this

RewriteEngine on
RewritePath /test/cat/item
RewriteRule ^([A-Za-z0-9\.-]+)/?$ item-display.php?bibid=$1 [L]

I think the problem is that it is looking at the whole URL and not just the last item ID part.

Nick Berardi
see updated answer
Nick Berardi
I think you're after RewriteBase...it doesn't appear to change the results though. Gets to the right page, then thinks bibid is set to 'display-item'. I'm reading into RewriteBase further hoping to find something in the docs.
Cory Dee
+1  A: 

The request is sub-processed so it extracts the rewritten URL's filename part I presume. Try adding the NS flag.

BYK
+4  A: 

You have to exclude the file you are redirecting to as that is also matched by the pattern:

RewriteCond %{REQUEST_URI} !/item-display\.php$
RewriteRule ^([A-Za-z0-9\.-]+)/?$ item-display.php?bibid=$1 [L]
Gumbo
Actually this is safer than mine I think :)
BYK
This makes perfect sense and works like a charm!
Cory Dee