0

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]
4

2 回答 2

3

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

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

表示它匹配任何内容,包括 /'s。

您可能想尝试:

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

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

于 2013-02-02T19:18:13.983 回答
1

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

于 2013-02-02T19:19:23.517 回答