2016-09-28 82 views
0

我想使用.htaccess重寫我的網址。我的舊網址是http://gametesting.in/infocomstudios/gamedetails.php?id=2,我需要將其更改爲以下http://gametesting.in/infocomstudios/demopage.html。在我的.htaccess中使用什麼代碼。我試着用下面的代碼:如何編寫.htaccess文件代碼以將舊網址更改爲新網址

RewriteCond %{QUERY_STRING} ^id=2$ 
RewriteRule ^gamedetails\.php demopage.html [L,R] 

但我得到了一個錯誤:

The requested URL /home/gamet/public_html/infocomstudios/demopage.html was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

而且我的新網址變爲:http://gametesting.in/home/gamet/public_html/infocomstudios/demopage.html?id=2

請幫我解決這個問題。

+0

這是一個標準的404錯誤。服務器找不到新頁面。可能需要處理?id = 2在html文件中不可接受。 – Linkan

+0

@Linkan感謝您的評論。但實際上我想重寫我的url.so,因此不需要創建該html文件 – Aswathy

+0

規則編寫的方式,您將發送給gamedetails.php?id = 2的人發送給demopage.html ,它必須存在才能工作。 – Linkan

回答

0

我剛剛調整你統治了一下保存路徑和查詢字符串:

RewriteCond %{QUERY_STRING} ^id=2$ 
RewriteRule ^(.*)gamedetails\.php(.*) $1demopage.html$2 [L,R] 

測試它的在線here

+0

Thanku @ copynpaste ..同時使用您的代碼時發生了同樣的錯誤。對於這個問題的其他解決方案?我第一次在.htaccess數據庫中 – Aswathy

+0

啊不真的讀這個錯誤。你確定該文件存在於這個位置嗎?並且ServerUser(在Apache上的www-data)可以訪問它? – danopz

+0

其實我沒有名字的網頁** demopage.html **當我打電話給這個** http://gametesting.in/infocomstudios/gamedetails.php?id=2 **然後只顯示如下的url ** http ://gametesting.in/infocomstudios/demopage.html** – Aswathy

0

試試這個我沒有測試它,請告訴我們,如果告訴我們,如果錯誤。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^infocomstudios/demopage.html$ infocom/gamedetails.php?id=2 [L] 
相關問題