wordpress的固定链接有很多种,前五种不需要伪静态,但是“漂亮”的固定链接(第五种)则需要伪静态组件,wordpress官方只提供了mod_rewrite的伪静态规则,但是IIS不支持mod_rewrite,网上找到的httpd.ini规则又太麻烦。
现在,只需要一个文件就可以解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?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'] = 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); ?> |
保存为.php文件,然后到iis里面把404页面指定为这个页面。
关于中文固定链接乱码问题
用编辑器(不要用记事本,最好用notepad++)编辑/wp-includes/class-wp.php第142行
将
1 |
$pathinfo = $_SERVER['PATH_INFO']; |
替换为
1 |
$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK"); |
再找到第147行
将
1 |
$req_uri = $_SERVER['REQUEST_URI']; |
替换为
1 |
$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK"); |
保存即可。 直接下载此文件
Lofty bye, sweet soul mate 🙂
Honourable bye, sweet chum 🙂
Lofty bye, genial alternative other 🙂
Very interesting info!Perfect just what I was looking for!
I consider something genuinely interesting about your site so I saved to favorites .
Obedient bye, genial alternative other 🙂
博主您好,我这有个交流群,是关于搜索引擎优化的,大家在一起交流网站排名,提高网站权重PR,希望您能加入,QQ群号:207057381
过一段看看你的快照!robots.txt更改要过一段时间才能有效果
谢谢。。。你的评论进垃圾箱了,一直没发现
此评论已河蟹
此评论已河蟹