Reputation: 673
After rewriting a link
http://localhost/schoolproject/posts.php?post_id=193
to
http://localhost/schoolproject/post/193
I can't access variable that are appended to the URL. For example:
http://localhost/schoolproject/post/193/?like=true
How do I access the variable like
with PHP $_GET['like']
I tried it but PHP tells me the variable is not set.
What is wrong here?
RewriteRule ^post/([^/]+)/?$ posts.php?post_id=$1 [L,NC]
RewriteRule ^post([^/]+)?$ posts.php [L,NC]
<?PHP
if (isset($_GET['post_id'],$_GET['like'])) {
echo "variables are set";
}else{
echo "not set";
}
?>
Upvotes: 0
Views: 71
Reputation: 2472
Use QSA
RewriteRule ^post/([^/]+)/?$ posts.php?post_id=$1 [QSA]
Or if QSA doesn't work for you, you can try this hack:
Options -MultiViews
RewriteEngine On
RewriteRule ^post/([^/]+)/?$ posts.php/?post_id=$1&%{QUERY_STRING} [L,NC]
Upvotes: 1