我有一個託管在共享Microsoft-IIS/8.5服務器上的網頁。 我沒有該服務器的管理員權限,而且我也無法訪問其配置文件,因此我無法確定URL rewrite模塊或HTTP redirect元素是否已正確安裝/設置。在共享主機上忽略web.config重定向
我想建立一個從名爲old_folder
的文件夾到名爲new_folder
的文件夾(都位於我的根目錄,即http://sharedhosting.com/myusername/)。 我放在根目錄下面的文件web.config
:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<sectionGroup name="system.webServer">
<sectionGroup name="rewrite">
<section name="rules" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
</configSections>
<system.webServer>
<rewrite>
<rules>
<rule name="attempt" stopProcessing="true" enabled="true">
<match url="^old_folder/$" />
<action type="Redirect" url="new_folder/" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
但所有我能得到的是一個403 - Forbidden: Access is denied.
(如果我離開的空old_folder
)或404 - File or directory not found.
(如果我刪除它)。
我嘗試使用HTTP Redirect
,在old_folder
放置Web.config
文件,其中包含
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://sharedhosting.com/myusername/new_folder/" />
</system.webServer>
</configuration>
但是這並沒有任何工作。
我知道我的Web.config
文件被讀取(如果它們中有錯誤,我可以得到500個錯誤)。我懷疑已經安裝了URL重寫,因爲如果存在folder
文件夾,則例如http://sharedhosting.com/myusername/folder
被重寫爲http://sharedhosting.com/myusername/folder/
(即,以斜槓)。
我的規則是否正確?我的主機是否阻止我重定向?如果是的話,我怎麼知道?
我在<rules>
標記後添加了一個<clear />
以放棄所有其他重寫規則,但它仍然沒有重定向任何內容。
我錯過了什麼?
最後一次編輯BOUNTY到期之前 爲了澄清,我的問題是「如何理解爲什麼服務器無法正確解釋/無視我的指示?」。
We came to the conclusion這可能是我的服務器奇怪的設置,我正在試圖「恢復工程」,並檢測是什麼讓服務器忽略重定向/重寫規則。
@Clément更新你的問題與你如何嘗試...其難以閱讀的評論 – Webruster
@Clément我提供了2個解決方案,其中一個用'IIS url'重寫另一個用'http handlers' – Webruster
對不起但我完全不知道如何使用'httphandlers'。我不熟悉'asp.net',所以我試圖測試,但我甚至不能告訴你涉及'httphandlers'的解決方案是否工作。正如我所說的,涉及'web.config'的解決方案不起作用,我非常樂觀。非常感謝您的幫助,我很感激。 –