2014-03-07 63 views
0

每個用戶可以訪問由www.example.com/profile/{username他們的帳戶的個人資料}將用戶重定向從舊網址到新

注:用戶名包含數字和字母只

例如: WWW .example.com的/資料/ michaelwatson www.example.com/profile/jenniferlee2

想從舊的URL重定向: www.example.com/profile/jenniferlee2

到新的S horter網址 www.example.com/jenniferlee2

我希望任何擁有舊書籤的人從舊網址轉到新網址,並且任何人只查看個人資料網址。其他任何內容都應保持不變。

這是我嘗試添加爲.htaccess,但得到的內部服務器錯誤

重寫規則/資料/ $ 1 [L]

+0

你怎麼知道一個配置文件不是從舊的一個新的URL的配置文件?例如,如果我訪問'http:// www.example.com/contact'並且由index.php處理,則根據您當前的規則,我將被重定向到'/ profile/contact'。 – Prix

回答

0

可以在根的.htaccess使用此代碼(*):

RewriteEngine On 

RewriteCond %{THE_REQUEST} \s/+profile/(\w+) [NC] 
RewriteRule^/%1? [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !^/profile/ 
RewriteRule ^(\w+)$ /profile/$1 [L] 
+0

嘗試了您的建議,並打破了其他鏈接(添加/配置文件到其他鏈接)。如果我點擊http://www.example.com/account/lostpass它說在這臺服務器上找不到請求的URL/profile/account/lostpass。 – Charles

+0

你沒有提供任何機制何時放'/ profile'和什麼時候沒有?你能澄清嗎? – anubhava

+0

你能解釋一下你指的是什麼機制,所以我可以提供正確的信息嗎? – Charles

相關問題