2015-04-22 91 views
1

我發現一個網站鏈接到我的網站與www.example.com/home.html不存在。我試圖建立一個重定向:301重定向到主頁返回404

Redirect 301 /home.html //www.example.com 

但它重定向到www.example.com/www.mysite.com

我可以使用Redirect,或做我必須做一個重寫?

回答

0

請使用重寫規則:

第一:

Options +FollowSymLinks 
RewriteEngine On 

然後

RewriteRule ^home.html$ http://www.example.com/ [r=301,nc,L] 
+0

這是否需要是其間開始和結束標記,如:。我在本地測試上述內容,但似乎無法使其正常工作。 – brandozz

+0

@brandozz不需要其他行或過濾器來將'http:// example.com/home.html'重定向到'http:// www.example.com /'。它必須在網絡中工作。確保沒有其他規則與此規則相矛盾。 – Ormoz

0

Redirect 301 /home.html //www.example.com

在這種情況下, ,目標URL(以斜槓開始)被認爲是相對於當前方案/主機的根。如果您有適當的設置DirectoryIndex,您可以重定向到/

例如:

Redirect 301 /home.html/