1

I've created a rewrite map that's working well:

.htaccess

RewriteRule ^([^/\.]+)/?$ index.php?page=${mymap:$1} [L]

mymap.txt

home 1
about 2
contact 3

So www.myurl/home works fine, but www.myurl/nonexistant_page doesn't exist in mymap.txt so I get an SQL error. Is there a way to check if the map exist and if not got to 404 page?

Pardoner
  • 1,011
  • 4
  • 16
  • 28

2 Answers2

3

You can specify a default value when there is no correspondence between key and values in your map.

${mymap:$1|default_value}

Then you can use this default value to trigger the 404 call in your index.php page by testing the query_string key called page.

By default, the default_value is the empty string. That may explain why you get an SQL error if your index.php page makes an SQL query with empty argument.

M'vy
  • 5,696
  • 2
  • 30
  • 43
1

I can't stress how important it is that you don't just slap the page ID into the end of your SQL query without sanitizing it first.

Anyway, perhaps surround your SQL query with a try/catch and send a 404 header in the event that an SQL Exception is caught.

noevidenz
  • 150
  • 1
  • 6
  • What do you mean my sanitizing it? Know any good articles I can read up on? I'm obviously missing something – Pardoner Jun 22 '11 at 14:16