我有這樣http://domain.com/index.php?user=test如何使用PHP重寫URL?
一個URL當用戶登錄時,我想說明像http://domain.com/user一個URL(用戶將是動態的)。
如何通過使用PHP重寫URL來實現這一目標?
我有這樣http://domain.com/index.php?user=test如何使用PHP重寫URL?
一個URL當用戶登錄時,我想說明像http://domain.com/user一個URL(用戶將是動態的)。
如何通過使用PHP重寫URL來實現這一目標?
你應該使用基於關閉的.htaccess的東西。以WordPress的,例如:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
這是說搶不存在(如你的情況‘用戶’),並重定向到主index.php
文件中的任何頁面。
然後,主index.php
可以抓住「用戶」,你可以用它從你的數據庫抓取數據並顯示你想要的任何東西。
EDIT--類似AlienWebguy的回答
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteRule ^like/(.+) /like.php?user=$1 [L]
</IfModule>
你會想看看mod_rewrite在.htaccess
添加在您的.htaccess重寫規則很簡單。首先,加入這一行到你的.htaccess mod_rewrite的激活:
添加您的規則來重定向頁面:
RewriteRule ^([^/]+)$ /yourpage\.php?user=$1
嘿克里,感謝您的答覆。我嘗試了你的代碼,但是當我試圖讀取用戶時,在我的頁面上發現了這個錯誤。錯誤是注意:未定義的索引:第1行的C:\ wamp \ www \ index.php中的用戶 – John
您能顯示您的PHP代碼嗎? –
<?php echo $ _REQUEST ['user']?> – John