2013-02-02 52 views
0

GET正在獲取文件擴展名和值。 這裏是我的.htaccess -GET參數正在獲取不需要的文件擴展名

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] 
+0

我不知道,如果正則表達式是貪婪的,但也可能是這個問題,因爲可能意味着(*)。 「包括斜線在內的所有內容」。 – mimipc

+0

'新代碼中的RewriteRule ^(([^ /] + /)* [^。] +)\。php'因爲'\ .php'增加了.php – Class

回答

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

的東西,如果任何人有任何更好的例子,請修改或作出評論。