php 程序最好使用 linux 的主機,但是很多人可能沒注意就買了 windows 主機的,比如我以前就使用了 windows 主機,但是 WordPress 使用 windows 主機一般都會遇到偽靜態和發送郵件的問題,偽靜態之後還可能遇到中文標籤 404 的問題。
什麼是偽靜態?如果你的網站使用是純靜態的 html 文件組成,而不是 phpasp.net 等程序語言,那麼網站的 url 也都是類似 http://www.example.com/11.html,這樣的網站是服務器上真是存在一個 11.html 文件。 WordPress 使用的是 php 程序語言,所以我們默認的 url 是類似:http://www.example.com/inde.php?p=111 這種類型的,偽靜態就是相對於靜態來講,如果我們認為的將 php 或其它程序語言製作的站點的 url 改成 http://www.example.com/111.html 這種形式,從 url 上來看這是一個靜態的網站,然是它是假的,所以為偽靜態
WordPress 後台提供了固定連接設置,在設置-》 固定連接頁面 可以很方便的設置 url 的結構,但是 windows 主機設置之後可能會出現找不到頁面的情況。如果你的主機支持自定義 404 錯誤頁面的話,先嚐試使用 404 頁面實現偽靜態,新建一個 404.php 文件,裏面代碼如下 (來源與互聯網):
- <?php
- // This is the default file for the site. Usually index.php
- $default = 'index.php';
- // The name of this file.
- // Set this value for the URL in Custom Error Properties of your website in IIS.
- // Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
- // 404 & 404;2 & 404;3 > URL (Requires a '/' prefix in IIS).
- $thisfile = '404-handler.php';
- //$_SERVER['ORIG_PATH_TRANSLATED']
- $_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
- $_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
- $_SERVER['ORIG_PATH_INFO'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_INFO']);
- $_SERVER['SCRIPT_NAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_NAME']);
- $_SERVER['PHP_SELF'] = str_replace($thisfile, $default, $_SERVER['PHP_SELF']);
- $_SERVER['PATH_INFO'] = false;
- $qs =& $_SERVER['QUERY_STRING'];
- $ru =& $_SERVER['REQUEST_URI'];
- $pos = strrpos($qs, '://');
- $pos = strpos($qs, '/', $pos + 4);
- $_SERVER['URL'] = $ru = substr($qs, $pos);
- $qs = trim(stristr($ru, '?'), '?');
- // Required for WordPress 2.8+
- $_SERVER['HTTP_X_ORIGINAL_URL'] = $ru;
- // Fix GET vars
- foreach ( $_GET as $var => $val ) {
- if ( substr($var, 0, 3) == '404') {
- if ( strstr($var, '?') ) {
- $newvar = substr($var, strpos($var, '?') + 1);
- $_GET[$newvar] = $val;
- }
- unset($_GET[$var]);
- }
- break;
- }
- include($default);
- ?>
然後將這個文件上傳至網站根目錄,注意可不是主題文件夾哦。然後到你的主機控制面板裏面設置 404 錯誤頁為這個 404.php 文件,我想一般的主機都會支持這個的。
缺陷:這樣設置之後,可能會遇到中文標籤頁打開還是 404 頁面的問題。
3.3.1 以上版本的設置方法的解決辦法如下 (摘自:龍飛揚博客),3.3.1 以下版本請看原處:在 WordPress 的 wp-includes 文件夾下面找到 rewrite.php 文件,用編輯器打開,搜索函數 get_extra_permastruct,原函數如下:
- function get_extra_permastruct($name) {
- if ( emptyempty($this->permalink_structure) )
- return false;
- if ( isset($this->extra_permastructs[$name]) )
- return $this->extra_permastructs[$name][0];
- return false;
- }
在第第一個 if 語句中加個"!"如下:
- function get_extra_permastruct($name) {
- if ( !emptyempty($this->permalink_structure) )
- return false;
- if ( isset($this->extra_permastructs[$name]) )
- return $this->extra_permastructs[$name][0];
- return false;
- }
保存即可。。