More

    WordPress 轉址與中文網址在 IIS 上會遇到的 404 問題

    以下包含暫時解法,因為是直接動WordPress Kernel

    1. WordPress 網址無法轉址(Permalinks)

    要修改 web.config 檔

    <?xml version="1.0" encoding="UTF-8"?>
    
    <configuration>
    
     <system.webServer>
    
     <rewrite>
    
     <rules>
    
     <rule name="wordpress" stopProcessing="true">
    
     <match url=".*" />
    
     <conditions logicalGrouping="MatchAll">
    
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    
     </conditions>
    
     <action type="Rewrite" url="index.php" />
    
     </rule>
    
     </rules>
    
     </rewrite>
    
     </system.webServer>
    
    </configuration>

    2. WordPress 中文網址無法正常轉址

    修改 wp-includes/ 底下的 class-wp.php

    $pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';

    改成

    $pathinfo = isset( $_SERVER['PATH_INFO'] ) ? mb_convert_encoding( $_SERVER['PATH_INFO'], 'UTF-8', 'Big5') : '';

    然後

    list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );

    改成

    list( $req_uri ) = explode( '?', mb_convert_encoding( $_SERVER['REQUEST_URI'], 'UTF-8', 'Big5' )  );

    3. WordPress 中文檔案上傳錯誤
    修改 wp-admin/includes/ 底下的 file.php

    $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );

    改成

    $fileTypeNameArr = explode( '.', $filename );
    $countNum = count( $fileTypeNameArr ) - 1;
    $fileExt = $fileTypeNameArr[$countNum];
    $filename = time() . '-' . rand( 0,999999999 ) . '.' . $fileExt;

    —-參考文獻—-
    [1] Using Permalinks – https://codex.wordpress.org/Using_Permalinks
    [2] [WordPress]中文網址,發生404錯誤,教你如何解決? – http://dev.brucelulu.com/topics/180
    [3] How to Setup WordPress Permalinks – https://gist.github.com/jonahvsweb/5479580
    [4] IIS permalinks compatibility – web.config not working? – http://stackoverflow.com/questions/27988710/iis-permalinks-compatibility-web-config-not-working
    [5] 解決 WordPress 在 IIS 中無法使用固定網址的問題 – http://www.minitw.com/archives/server/solved-can-not-be-used-in-iis-wordpress-permalink-issue.htm?variant=zh-tw
    [6] WordPress小技巧(1):解決中文檔名圖片無法上傳問題 – http://www.cc.net.tw/2013/07/434/

    Source : https://blog.jimmmmy.com/2016/09/05/wordpress-iis-permalinks-404-error/

    Recent Articles

    spot_img

    Related Stories

    Stay on op - Ge the daily news in your inbox