Forum Moderators: phranque

Message Too Old, No Replies

quick url rewrite question

I don't see what I'm doing wrong

         

mcvoid

2:06 am on Jul 3, 2009 (gmt 0)

10+ Year Member



Hey all,

I want /page/somenumber to rewrite as /index?page=somenumber.
The line I have in the .htaccess is:

RewriteRule ^page/(0-9+) ./index.php?page=$1

But I'm getting a 404 error! It says /page/1 not found. What am I missing? I have other near-identical rules that all work, and I don't see what's so different. Any help?

g1smd

2:23 am on Jul 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's a period before the slash that shouldn't be there.

You need to add the [L] flag to this rule.

mcvoid

2:34 am on Jul 3, 2009 (gmt 0)

10+ Year Member



The period before the slash is because it's not in the root directory and would redirect to a non-existent file one directory up if I didn't include the period. What does the [L] stand for?

g1smd

2:48 am on Jul 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



*** redirect to a non-existent file ***

This code is not for a 'redirect'. What you have there is a 'rewrite'. Is that what you want?

The [L] stands for Last rule. It stops processing here, and should always be included unless you know exactly why you need to omit it.

jdmorgan wrote a very good post about this in the last 24 hours in an earlier thread here.

mcvoid

3:11 am on Jul 3, 2009 (gmt 0)

10+ Year Member



I meant rewrite, yes. I figured it out - i changed the ^page/(0-9+) to ^page/([0-9+]) and it seems to be working now, though I'm not sure why that's important. Maybe I should learn regex's better...

Well, thanks for your help. I learned something new, and that's always good.

jdMorgan

3:25 am on Jul 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at your server error log to see what filepath that rewrite is resolving to. Compare the path to the desired filepath, and correct the code as needed.

AFAIK, "./" is not a option here. Try either no slash or a slash plus the full path from root. mod_rewrite in .htaccess cannot traverse above the Web root.

Jim

mcvoid

3:38 am on Jul 3, 2009 (gmt 0)

10+ Year Member



I took the "./" and it still worked, so i think it's good now. I remember reading somewhere that, when it's not part of the regex, the period gets substituted for the current document path.