GET参数正在获取不需要的文件扩展名

时间:2013-02-02 19:01:58

标签: php .htaccess

GET正在获取文件扩展名以及值。 这是我的.htaccess -

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^test/(.*)/(.*)/$ /Test3.php?u=$1&i=$2 [NC,L]
RewriteRule ^test/(.*)/(.*)$ /Test3.php?u=$1&i=$2 [NC,L]
RewriteRule ^test/(.*)/$ /Test3.php?u=$1 [NC,L]

文件Test3.php是这样的 -

<?php
echo $_GET['u'];
echo '<br/>';
echo $_GET['i'];
?>

网址我正在通过 - http://example.com/test/something/more/

我的浏览器输出 -

something/more.php

所需输出的位置

something
more

我已经抓住了整个网站来解决这个问题,但没有运气。不知道为什么我最后得到那个php而且http://example.com/test/之后的完整值只是第一个参数。

请帮忙!

全部谢谢!我相信这个问题来自这条线。请求提出解决方案。

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.example.com/$1 [R=301,L]

2 个答案:

答案 0 :(得分:3)

我不是RewruteRules的专家,但我知道一些正则表达式和.*

^test/(.*)/(.*)/$

表示它匹配包括/的所有内容。

您可能需要尝试:

RewriteRule ^test/([^/]+)/([^/]+)/?$ /Test3.php?u=$1&i=$2 [L,NC]
//removed this one because they are basically the same
//by adding '/?' it says that the slash is optional
RewriteRule ^test/([^/]+)/?$ /Test3.php?u=$1 [L,NC]

有人可能想对正则表达式提出建议,但我认为它可以用于您的目的。

编辑:或者您可以执行https://stackoverflow.com/a/14663292/1700963

之类的操作

如果有人有更好的例子,请编辑或发表评论。

答案 1 :(得分:1)

我找到了一个页面,描述了我在评论中提到的贪婪的事情: http://www.mspo.com/how-to/greed-in-apache-rewrite-rules.html