Advay Ratan
Advay Ratan

Reputation: 249

.htaccess not allowing $_GET to work

My .htaccess file is currently:

RewriteEngine on
RewriteRule ^display/([0-9]+) display.php?id=$1

However, in display.php when I try to access the value for $_GET['id'], PHP says there is no value.

Currently display.php?id=1 works fine but display/1 doesn't work. I have also tried to see if display/id=1 or display.php/1 work but none do.

I'm new to .htaccess, so I have no clue what I'm doing wrong. Please help, thanks in advance.

Upvotes: 5

Views: 770

Answers (1)

Yuseferi
Yuseferi

Reputation: 8670

You just need add "QueryString Append" option, it :

 RewriteRule ^display/([0-9]+) display.php?id=$1 [QSA,L]

and if it doesn't work try :

 RewriteEngine on
 Options -MultiViews
 RewriteRule ^display/([0-9]+) display.php?id=$1 [L]

just for your info :

The QSA flag means to append an existing query string after the URI has been rewritten. Example:

URL=http://example.com/foo/bar?q=blah

Rule:

RewriteRule ^foo/(.*)$ /index.php?b=$1

Result=/index.php?b=bar

Notice how the q=blah is gone. Because the existing query string is dropped in favor of the one in the rule's target, (b=$1). Now if you include a QSA flag:

RewriteRule ^foo/(.*)$ /index.php?b=$1 [QSA]

The result becomes=/index.php?b=bar&q=blah

.htaccess flag list

  • C (chained with next rule)
  • CO=cookie (set specified cookie)
  • E=var:value (set environment variable var to value)
  • F (forbidden - sends a 403 header to the user)
  • G (gone - no longer exists)
  • H=handler (set handler)
  • L (last - stop processing rules)

Last rule: instructs the server to stop rewriting after the preceding directive is processed.

  • N (next - continue processing rules)
  • NC (case insensitive)
  • NE (do not escape special URL characters in output)
  • NS (ignore this rule if the request is a subrequest)
  • P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
  • PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
  • R (temporary redirect to new URL)
  • R=301 (permanent redirect to new URL)
  • QSA (append query string from request to substituted URL)
  • S=x (skip next x rules)
  • T=mime-type (force specified mime type)

for more information take a look at RewriteRule Flags

Upvotes: 6

Related Questions