Forum Moderators: phranque

Message Too Old, No Replies

.htaccess appending querystring parameters

         

ffoeg

11:16 am on May 14, 2008 (gmt 0)

10+ Year Member



Hi there.

I'm still relatively n00b when it comes to RegEx and .htaccess, so please excuse any ignorance that might show through :)

Let's assume I have a website URL,

http://example.org/articles/
. This URL will be remapped to
http://example.org/index.php?page=articles
.

Then we have a second website URL, but one that looks more like

http://example.org/articles/?id=329
. This URL will need to be remapped to
http://example.org/index.php?page=articles&id=329
.

Now, I've read about the [QSA] flag that can be applied to the RewriteRule directive (is that what it is called?), and it still doesn't seem to help me.

Basically, this is the .htaccess code that I already have:


RewriteCond %{REQUEST_URI} ^/([a-z]+)/? [NC]
RewriteRule (.*) /index.php?page=%1

And that is about as far as I can get. I have tried all manner of different variations in order to append the

?id
to the original querystring, but nothing seems to work.

I'd really appreciate it if anyone could help me in this. Thanks.

jdMorgan

3:05 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First site, code in example.org/.htaccess:

RewriteCond $1 !^index\.php$
RewriteRule ^([a-z]+)/?$ /index.php?page=$1 [L]

Second site, code in example.org/articles/.htaccess:

RewriteCond $1 !^index\.php$
RewriteRule ^$ /index.php?page=articles [QSA,L]

-or-
Second site, code in example.org/.htaccess:

RewriteRule ^articles/?$ /index.php?page=articles [QSA,L]

The checks for NOT index.php prevent 'infinite' rewrite looping.

Jim

[edit] Fixed disastrously-bad formatting and errors (due to fatigue?). :o [/edit]

[edited by: jdMorgan at 2:15 pm (utc) on May 16, 2008]

ffoeg

8:10 am on May 16, 2008 (gmt 0)

10+ Year Member



Awesome. I'll have to take a look at this and try and get it working when I get home, but thanks for the time taken to reply ^_^