2013-02-26 26 views
0

我在重定向服務器上不存在的整個目錄時遇到問題。如何永久重定向不再存在的目錄(通過.htaccess)

以下所有變化都不起作用,我只是得到404頁面未找到。

.htaccess文件看起來像這樣:

redirect 301 /non_existent_directory/ http://my.website.com/existent_directory/ 

是否有可能使用這種重定向301指令?或者這隻能通過mod_rewrite解決?

感謝

我甚至嘗試:

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com\/non_existent_directory\/$ [NC] 
RewriteRule ^(.*)$ http://my.website.com/existent_directory/ [R=301,L] 

沒有運氣...

回答

1

Redirect文檔時,我會說

Redirect 301 /non_existent_directory http://my.website.com/existent_directory 

Redirect 301 /non_existent_directory /existent_directory 

應該工作,只要你是allowed在.htaccess文件中使用它。另請參閱Troubleshooting .htaccess文件。儘管如此,您應該在沒有301的情況下進行測試,以防止客戶端緩存重定向錯誤。

如果這不起作用,你可以嘗試當然

RewriteEngine On 
RewriteRule ^/?non_existent_directory(.*)$ /existent_directory$1 [R,L] 

RewriteRule但這相當於上述Redirect指令。

+0

我被允許使用.htaccess - 它在我的整個服務器中普遍使用。然而,只要我在「http:// my.website.com/non_existent_directory」或「http:// my.website.com/non_existent_directory /」或「http://我的網站上點擊任何內容,該指令就會生成404 PNF @OlafDietsche .website.com/non_existent_directory/anypage.html' – 2013-02-26 13:25:05

+0

我已經使用其他重定向301的其他.htaccess文件fpr丟失的文件,他們已經工作。這是我第一次嘗試重定向一個不存在的整個目錄... – 2013-02-26 13:30:31

+0

@ H.Ferrence如果沒有日誌信息,很難判斷真正發生了什麼。無論如何,你可以嘗試上面的其他選擇。 – 2013-02-26 13:39:28