2017-03-16 27 views
-2

顯示的用戶名我怎麼能傳遞一個用戶名以這種格式在我的網址例如http://www顯示。 example.com/username代替http://www.example.com/?user =用戶名 任何幫助將很長的路要走,感謝如何爲URL的一部分使用PHP

+2

你應該看看[htaccess從url中刪除參數](http://stackoverflow.com/questions/37722694/htaccess-remove-the-parameter-from-url) – Neil

+0

什麼是它的正確格式htaccess –

+0

添加了答案。您將.htaccess放入您希望縮短網址縮短時間的文件夾中。 – Neil

回答

0

這裏是你如何把它寫:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?user=$1 [NC] 

如果你想/category/username模擬/category.php?user=username,則:

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^category/(.*)$ category.php?user=$1 [NC] 
+0

我與本地主機服務器使用WAMP但在試運行,我得到這個錯誤信息「內部服務器錯誤」 –

+0

這個我什麼,我在Apache的錯誤日誌錯誤的參數行的RewriteCond%{} REQUEST_FILENAME看!-f –

+0

它完美罰款測試我的結局。我似乎無法重現這個問題。 – Neil