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]
2
  • 1
    add your rewrite rule, you are probably missing [QSA] , but it's just a guess since there's no code. Commented Jun 6, 2014 at 12:39
  • 1
    I want many things, yet you do not want to show us your rewrite rules? Commented Jun 6, 2014 at 12:39

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

2 Comments

Alright, but what if somebody types /staff/new&a=b? I will get a 500 Internal Server Error
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.