重写链接后
http://localhost/schoolproject/posts.php?post_id=193
到
http://localhost/schoolproject/post/193
我无法访问附加到网址的变量。例如:
http://localhost/schoolproject/post/193/?like=true
如何使用PHP like
$_GET['like']
我试了但是PHP告诉我变量没有设置。
这里有什么问题?
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";
}
?>
答案 0 :(得分:1)
使用QSA
RewriteRule ^post/([^/]+)/?$ posts.php?post_id=$1 [QSA]
答案 1 :(得分:1)
使用QSA
RewriteRule ^post/([^/]+)/?$ posts.php?post_id=$1 [QSA]
或者如果QSA不适合你,你可以试试这个黑客:
Options -MultiViews
RewriteEngine On
RewriteRule ^post/([^/]+)/?$ posts.php/?post_id=$1&%{QUERY_STRING} [L,NC]