1. 程式人生 > 其它 >(收藏)網站首頁和欄目頁等 index.html 301跳轉 不帶 index.html 主域

(收藏)網站首頁和欄目頁等 index.html 301跳轉 不帶 index.html 主域

技術標籤:論跑路的藝術伺服器iiswindows serverurl

其實參考大部分網站都沒有做所謂的 index.html 301跳轉主域,大部分都是隱藏主域後面的index.html,其實參考搜尋引擎影響感覺差不多。

看了下國外網站 針對 字尾檔案 index.html大部分是做404或者301處理。

但是對於強迫症對seo優化,可能需要用到!

環境:Windows寶塔版6.9 IIS10;

教程:網站目錄 web_config資料夾下,開啟rewrite.config配置檔案(這是寶塔環境下的路徑配置,非寶塔環境直接新增配置程式碼到根目錄web.config裡面配置檔案。)

新增配置程式碼:

<!-- index.html 301 -->
	
	<rule name="301Rdeirect" stopProcessing="true">
    <match url="(.*)"></match>
    <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^$" />           
    </conditions>
    <action type="Redirect" url="https://你的域名/{R:0}" redirectType="Permanent" />
  </rule>

  <rule name="homeIndex">
    <match url="^index.html$" ignoreCase="false"></match>
    <action type="Redirect" url="/" appendQueryString="false" redirectType="Permanent" />
  </rule>

<!-- index.html 301 -->

檢驗一下瀏覽器輸入帶index.hml 會直接301 跳轉到不帶index.html主域。

狀態碼檢測一下:

欄目頁 index.html 跳轉 當前 主域目錄 不帶index.html

這時需要拷貝web.config檔案到相應欄目頁目錄下,開啟新增配置程式碼。

 <!-- 欄目頁 index.html 301 -->
        <rules>

          <rule name="301Rdeirect" stopProcessing="true">
            <match url="(.*)"></match>
            <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}" pattern="^$" />           
            </conditions>
            <action type="Redirect" url="https://www.xx.com/xx/{R:0}" redirectType="Permanent" />
          </rule>

          <rule name="homeIndex">
            <match url="^index.html$" ignoreCase="false"></match>
            <!-- 規則 -->
            <action type="Redirect" url="https://www.xx.com/xx/" appendQueryString="false" redirectType="Permanent" />
          </rule>

          </rules>

  <!-- 欄目頁 index.html 301 -->

檢驗一下瀏覽器輸入帶index.hml 會直接301 跳轉到不帶index.html主域。

狀態碼檢測一下:

PS:絕客