2013-07-17 22 views
0

我想加載一個頁面(/user/profile.php),只要URL是sitename.com/u/[user_nicename] 如何通過mod重寫來實現這個?寫入mod_rewrite加載一個特定的文件

我曾嘗試以下,但它沒有正確重定向(顯示404錯誤)

這裏是我的htaccess的內容,

RewriteEngine On 
RewriteRule ^u/([^/.]+)/?$ /user/profile.php [L] 

(我在 'U' 創造了這個.htaccess文件目錄,這樣當example.com/u/[something]這樣的請求被創建時,它會查找[something]文件,當沒有找到它時,它會嘗試找到'u'目錄,我已經寫了這個重定向)

請幫助,我所要做的就是加載一個特定的文件即/user/profile.php每當一個請求就像sitename.com/u/[user_nicename] 謝謝!

回答

0

試試這個:

 RewriteRule ^/u/(.*) /user/profile.php [L] 
+0

那不行。仍然沒有發生重定向,說沒有找到頁面。 – Rao

+0

你應該把它放在根目錄下。 – srain

0

因爲,你有這樣的.htaccess子目錄u裏面是隱含的,在規則中不是必需的。

RewriteEngine On 
RewriteRule ^([^/]+)/?$ /user/profile.php [L] 
相關問題