drjmrg8766 2018-10-09 11:06
浏览 63

PHP:$ _GET [''] superglobal在使用.htaccess清理URL后不从URL获取值

I have a problem with $_GET['']. Before applying .htaccess rules on URL every things was working fine, when I clean the URL's with .htaccess file now the echo $_GET['id'] give me this error (Notice: Undefined index: id in C:\wamp64\www\Test\show.php on line 3). The new clean URL's work fine without parameter but when I tried to send parameter it does not send id. I don't Know what to do. I have searched for this problem more then 10 hours but no result.

my .htaccess file content:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^show/([0-9]+)/([0-9a-zA-Z_-]+) show.php?id=$1&name=$2 [NC,L]

the show.php page where I want to display the values from URL

<?php
$myvar = $_GET['id']."<br>";
$myvar1 = $_GET['name'];
echo $myvar;
echo $myvar1;
?>

this URL have no problem (http://localhost/Test/show.php?id=120&name=ahmad)

**but in this url (http://localhost/Test/show/120/ahmad) this error is happening **

Notice: Undefined index: id in C:\wamp64\www\Test\show.php on line 3 Notice: Undefined index: name in C:\wamp64\www\Test\show.php on line 4

I have dis comment the mod_rewrite.os in httpd.conf file as will.

please help me thanks.

  • 写回答

1条回答 默认 最新

  • duanlao6573 2018-10-09 16:17
    关注

    Change your RewriteCond:

    RewriteCond %{REQUEST_FILENAME} -f
    

    to

    RewriteCond %{REQUEST_FILENAME} !-f
    

    The second one means if the path is NOT a file on the server, so that's what you want. I guess the first one means only if the path IS a file.

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)