2014-07-17 123 views
0

我們重新設計了一個網站,其中一些網頁不復存在。我在大多數舊頁面上做過301重定向,但並不是所有這些舊頁面都仍在我的文件夾中,而是希望在.htaccess文件中重定向所有內容。下面是我現在的整個.htaccess文件。將html文件重定向到php文件可以正常工作,但是嘗試從php文件重定向到php文件不起作用。我試圖離開新網頁的第一部分(到.com),但我仍然收到404錯誤。我已經嘗試了多個其他頁面,每次都得到相同的結果,從HTML指向PHP的作品,但從PHP到PHP不。有什麼建議麼?301使用.htaccess重定向php文件

Options +FollowSymLinks 
RewriteEngine on 
Redirect 301 /folder1/page1.php http://www.example.com/folder2/page2.php 
Redirect 301 /folder1/page1.html http://www.example.com/folder2/page2.php 

回答

1
RewriteEngine On 
RedirectMatch 301 folder1/(.*) folder2/$1 
RewriteRule ^(.*)\.html$ $1.php [L] 

編輯:

RedirectMatch需要在文件夾1一切,並重定向到文件夾2

RewriteRule然後採取所有的HTML文件擴展名和重寫他們到PHP

+0

soudln't它是' RedirectMatch 301 folder1 /(.*)folder2/$ 1'? – Bobot

+1

不錯,我修好了:) –

+1

對不起,我是新手,你能解釋一下這是什麼意思嗎? – user3851100