PHP从url rewrite中获取显示.php的值

时间:2015-07-31 10:18:37

标签: php .htaccess url-rewriting query-string

我在htaccess文件中使用了url重写,将2个查询字符串值显示为/ item1 / item2

当我得到item2时,它最后有.php。我的重写中是否有一些我不知道的东西?

接听电话

$card = $_GET['card'];
$card; // This value has .php after the value

重写

RewriteRule ^player-score\/([^\/]+)\/([^\/]+)\/?  /player-score.php?id=$1&card=$2 [QSA,NC,L]

完整示例网址

www.example.com/player-score.php?id=1&card=45

3 个答案:

答案 0 :(得分:1)

我发现了这个问题,我需要在查询字符串重写规则下面移动下面的规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

答案 1 :(得分:0)

尝试此规则:

 INFO  WEBrick 1.3.1
 INFO  ruby 2.2.2 (2015-04-13) [x86_64-linux]
 INFO  WEBrick::HTTPServer#start: pid=20475        port=9292
127.0.0.1 - - [31/Jul/2015:16:57:48 +0530] "GET /Rack.rb?    name=rfg&age=dfg&email=dfg&hobbies=d HTTP/1.1" 200 - 0.0006
127.0.0.1 - - [31/Jul/2015:16:57:48 +0530] "GET /favicon.ico HTTP/1.1"  200 - 0.0004
 127.0.0.1 - - [31/Jul/2015:16:57:54 +0530] "GET /Rack.rb?     name=rt&age=21 HTTP/1.1" 200 - 0.0005

答案 2 :(得分:0)

你能试试吗?我对你的重写做了一些小编辑。

RewriteRule ^player-score/([^\/]+)/([^/.]+)/?$  /player-score.php?id=$1&card=$2 [QSA,NC,L]