.htaccess or PHP?

Hi folks!

I think this is a .htaccess issue but I’m not pretty sure…
Here’s my .htaccess file :


RewriteCond %{REQUEST_URI} events
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)$ index.php?page=$1&a=$2 [L]

and here’s the part of the ‘landing’ php file :


if ($a == "new") {
// load the form
}
if (is_numeric($a)) {
	$database->eventHandler("this_event", $session->username, $a);
} // end if a == event_id

which is working fine as long as the variable $a is NOT numeric. When it IS a numeric value ($a = 5 i.e.) I get an Error 404… Any other value is being propagated, it’s just the numeric values causing the error.
As always, your help is appreciated!

It’s definitely the .haccess, cause when I use the ugly


<a href='index.php?page=events&a=".$events_rows['id']."'>LINK</a>

link, it is working! I’m not an expert with .htaccess and regex so I will need your help guys to figure out what’s wrong with


RewriteCond %{REQUEST_URI} events
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)$ index.php?page=$1&a=$2 [L]

when the ‘a’ is numeric value… Thank you advanced.
Regards

Google is our friend!


RewriteCond %{REQUEST_URI} events
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_0-9]+)$ index.php?page=$1&a=$2 [L]

If you have a more elegant solution, feel free ti post… :slight_smile:

What you currenly have:


RewriteCond %{REQUEST_URI} events
RewriteRule ^([a-zA-Z_]+)/([[COLOR="RoyalBlue"]a-zA-Z_[/COLOR]]+)$ index.php?page=$1&a=$2 [L]

The part in blue are the characters accepted for the a parameter. So any character, either lower case or upper case, and underscores. Indeed, that won’t match digits :slight_smile:

To accept digits only, change it to


RewriteCond %{REQUEST_URI} events
RewriteRule ^([a-zA-Z_]+)/([0-9]+)$ index.php?page=$1&a=$2 [L]

If you want to match both digits and characters, well, I’m sure you’ll figure that out, it’s not hard :slight_smile:

Hi Viktor!

Actually, Rémon is partially correct. The problem, however, is also in your script as $a is a character (whether that character is a digit or not is irrelevant). Make sure that INTVAL($a) is > 0 (the default if there are only letters) and that should solve that problem for you.

Regards,

DK