2014-09-04 52 views
1

我htaccess的樣子以下htaccess的沒有返回所需的值

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?module=modelname&action=pagename&reff=$1 

我已經使用的index.php作爲控制器來渲染使用參數模塊和行動的看法,

我想重寫以下網址 http://example.com/username/splash

,並希望得到的用戶名,但是當我打印$ _GET [ 'REFF']它打印的index.php

任何人都可以請建議什麼是錯的?

感謝

回答

1

你看到$_GET['reff']=index.php因爲你重寫規則運行兩次。首先在/username/splash URI上,然後第二次在/index.php URI。這是由於您的URI模式^([^/]+)/([^/]+)/?$與兩個URI都匹配。

爲了防止你需要有您的規則這樣的這種不必要的行爲:

# if request is not for a file 
RewriteCond %{REQUEST_FILENAME} !-d 
# if request is not for a directory 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?module=modelname&action=pagename&reff=$1 [L,QSA]