0

So my staff.php?action=[action] file is rewritten to /staff/[action] where action can take 3 values new/edit/delete.

I want to display success or failure messages on submission. I tried to redirect to /staff/new&error=[error] or /staff/new?error=[error].

However, the var_dump($_GET) only returns the action's query string.

The only solution I found is /staff?action=[action]&error=[error], but I don't like it. Is there any way of rewriting my rules?

I don't want /staff/new/error/[error]

## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

RewriteRule ^staff/(.+)$ /staff.php?action=$1 [L]
Emanuel Vintilă
  • 1,911
  • 4
  • 25
  • 35

1 Answers1

2

You can use QSA flag to add query string to your forwarded page

RewriteRule ^staff/(new|edit|delete)$ /staff.php?action=$1 [L,QSA]
Justin Iurman
  • 18,954
  • 3
  • 35
  • 54
  • Alright, but what if somebody types `/staff/new&a=b`? I will get a `500 Internal Server Error` – Emanuel Vintilă Jun 06 '14 at 12:43
  • Why would you ? It would be forwarded to `/staff.php?action=new&a=b`. Anyway you should always check your GET parameters for security reasons. Is there only `error` parameter that could be added to your query string in this case ? If yes, then a condition can be added to match only that possibility – Justin Iurman Jun 06 '14 at 12:48