skip to Main Content

I have written a redirect to change quiz.php?quiz=1 to /quiz/1 however PHP can no longer pickup the GET Variables, is there anything i’m missing? This is my htaccess file:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^quiz/([^/]*)$ /quiz.php?quiz=/$1 [QSA,L]

2

Answers


    1. You have error in RewriteRule ^quiz/([^/]*)$ /quiz.php?quiz=/$1 [QSA,L]
      There should not be slash at redirect target, so correct is RewriteRule ^quiz/([^/]*)$ /quiz.php?quiz=$1 [QSA,L]

    2. I tried this on localhost and it is working properly. Try debugging via e.g. var_dump($_GET);

    Login or Signup to reply.
  1. In this specific case, you probably need to disable content negociation and AcceptPathInfo features by adding the following lines to your .htaccess file:

    AcceptPathInfo off
    Options -MultiViews
    

    Content negociation can internally “rewrite” “quiz” into “quiz.php”. And AcceptPathInfo “quiz.php/a/b/c” to “quiz.php” with $_SERVER['PATH_INFO'] = ‘/a/bc/c’. They both happen before rewriting, bypassing your rule.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search