Reputation: 249
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
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
Last rule: instructs the server to stop rewriting after the preceding directive is processed.
for more information take a look at RewriteRule Flags
Upvotes: 6