简体   繁体   English

使用重写规则时,PHP $_GET 值不起作用

[英]PHP $_GET values doesn't work when using rewrite rules

In profile user $_GET doesn't work fine.在个人资料用户 $_GET 不能正常工作。

I'm using URL Rewriting我正在使用 URL 重写

its它的

RewriteBase /pline/
   RewriteEngine On
   RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
   RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1
  • if user url is (website.com/username?photos) not working如果用户 url (website.com/username?photos) 不起作用
  • if user url is (website.com/profile.php?photos) working如果用户 url (website.com/profile.php?photos) 有效

    if(isset($_GET['friends'])){ echo 'Friends area!'; } else{ if(isset($_GET['photos'])){ echo 'Photos area!'; } else{ echo 'Profile area!'; } }

How can I solve this problem?我怎么解决这个问题?

thank you谢谢你

according to your rewrite rules, there is only a one variable called username根据您的重写规则,只有一个名为username变量

so in your php, only $_GET['username'] will get values所以在你的 php 中,只有$_GET['username']会得到值

That is default variable is username.那是默认变量是用户名。 so you should use this kind of links: website.com/value_for_username所以你应该使用这种链接: website.com/value_for_username

if you want more variables, use website.com/value_for_username&var1=value1&var2=value2 and so on.如果您想要更多变量,请使用website.com/value_for_username&var1=value1&var2=value2等。 and also update rewrite rules to match it if necessary.并在必要时更新重写规则以匹配它。

$_GET['photos'] are definend in both cases! $_GET['photos'] 在这两种情况下都是定义的!

All the time this code go to echo "Photos area"这段代码一直在回显“照片区域”

Note, that in you exemple you username url no have PHP extension!请注意,在您的示例中,您的用户名 url 没有 PHP 扩展名!

You can try with value in $_GET parameter, try some like website.com/username.php?section=photos您可以尝试使用 $_GET 参数中的值,尝试一些类似 website.com/username.php?section=photos

swich($_GET['section']){
   case 'product':
     echo "Product section";
   break;
  ....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM