Forum Moderators: phranque

Message Too Old, No Replies

Simple mod rewrite question

Simple mod rewrite question + dyanmic pages

         

richiebman

6:00 pm on Oct 26, 2004 (gmt 0)

10+ Year Member



Hello all,

Just a quick one and very simple. I have the following line in my htaccess file which works fine.

RewriteRule ^home_(.*)$ home?180_version=$1

But know I have new pages popping up and need to cover this dynamic side. The below line works fine for a present page:

RewriteRule ^day25_(.*)$ day25?180_version=$1

However the number 25 will be changing as new pages are created. How do I accomodate this? I have tried:

RewriteRule ^day[^/]_(.*)$ day[^/]?180_version=$1

but I get a 404 error.

Thanks in advance,
R

jdMorgan

8:31 pm on Oct 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The pattern you used would accept any single character not equal to a slash, and then require the next character to be an underscore. Therefore, it's likely that the pattern never matched and the rule was never invoked, so you got a 404 because the originally-requested URL did not actually exist. Also, you did not create or reference a second back-reference, so the "day number" would not have been passed into the new URL anyway.

Try this, which accepts one or more digits preceding the slash and passes them to the substitution:


RewriteRule ^day([0-9]+)_(.*)$ /day$1?180_version=$2

Jim

richiebman

10:01 pm on Oct 26, 2004 (gmt 0)

10+ Year Member



Cheers JDM. I had to change what you gave me though, albeit very slightly.

RewriteRule ^day([0-9]+)_(.*)$ day$1?180_version=$2

I removed the forward slash you'd put in before the second day. But I think that I'll have to put it back in when I put the site online as my home test server setup is different to my online one.

Thanks again,
R