PHP troubles

theprovider777

Registered Member
Joined
Sep 3, 2007
Messages
93
Reaction score
94
I'm not quite sure where to post this, but if anyone with some PHP knowledge could help me out, I'd appreciate it.

I have mod_rewrite set to redirect in this manner:

domain.com/page/action => domain.com/index.php?page=$1&action=$2

I also added an extra rule to handle a request with no $action
ie. domain.com/page => domain.com/index.php?page=$1
(not sure if this was necessary..I've tried it both ways..)

Now, whenever I try to request a $page without an $action, it appears that the variables aren't even set.

To be clearer:

<?php
$page = $_GET['page'];
$action = $_GET['action'];
?>

When I access a page with both a page and an action, ie. domain.com/page/action/, everything works fine and both variables get the proper values. Without an action, the varibles are set as follows:

$page is empty
$action is index.php

What I want is for $page to be set, and $action to be empty.

I'm pulling my hair out over this. Can someone help me?
 
Rather than delete, please share your fix. It may help others.

Good point. I had actually thought about that, then I got lazy. :o

Originally, I had the following rewrite rules in my .htaccess:

RewriteRule ^([^/]*)/$ /index.php?page=$1
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?page=$1&action=$2 [L]

For some reason, it wouldn't work like that, but if I simply did them in descending order (2-1), it worked:

RewriteRule ^([^/]*)/([^/]*)/$ /index.php?page=$1&action=$2
RewriteRule ^([^/]*)/$ /index.php?page=$1 [L]

I don't know enough about mod_rewrite to say WHY it's like this, but perhaps it will help someone. (Thanks for spurring me into action, brittany46 :p )

PS. An admin might also think of renaming this to mod_rewrite troubles .. ?
 
Back
Top