2013-10-11 31 views
0

尋找我的問題一個答案之後,我還是難倒這一點。我正在研究一個允許用戶創建個人資料的小型社交腳本,但我希望他們的個人資料網址很短。我編輯了.htaccess文件,它完美的工作!的.htaccess URL重定向但不顯示的索引頁

例如 www.site.com/username 重定向到 www.site.com/profile.php?user=username

但是,如果你只是去到索引頁面。它顯示了profile.php但有一個空的GET變量...

這裏是我的.htaccess代碼

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ profile.php?name=$1 [QSA,L] 

提前感謝!

+0

這個'.htaccess'的位置和'profile.php和index.php'文件的位置是什麼? – anubhava

+0

主目錄(/ public_html)。他們需要在不同的目錄中嗎?真的希望使它成爲www.site.com/username而不是www.site.com/profile/username –

+0

'主文件夾中的profile.php和index.php(/ public_html)。' – anubhava

回答

0

我想,你要解決的時候有一個問題:http://www.site.com/(不www.site.com/index.php)。 .htaccess看到比文件「」不存在並重定向到www.site.com/profile.php?user=(使用空參數用戶)。嘗試modyfy的.htaccess這個(使用^(.+)$代替^(.*)$):

RewriteEngine One 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ profile.php?name=$1 [QSA,L] 
0
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+?)/?$ profile.php?name=$1 [QSA,L] 

/?也將防止任何尾隨的斜槓(如果存在的話)。