URL Mod-Rewrite Workaround for IIS 6.0 and WordPress
I found that the existing solution for using pretty permalinks with WordPress and IIS is good
and lightweight, but I needed something a little more robust that fixed as many differences as possible between Apache and IIS.
This code uses the same idea as the above, but fixes more values in _SERVER and resolves a problem with _GET. It will also work with later versions (2.8+) of WordPress.
<?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);
?>
116 Comments
→
Trackbacks & Pingbacks
- Pretty Wordpress Permalinks on IIS » tech.einaregilsson.com
- Permalinks and mod_rewrite Headaches in Wordpress with IIS | Dot Net Yuppie
- Brian On Software » Blog Archive » Migrating a Wordpress site from BlueHost to WebHost4Life
- sawathee » Blog Archive » Using Permalinks
- Permalinks on a GoDaddy WIMP setup « 49thLatitude
- windows+IIS下完美设置wordpress伪静态 | 陈方毅的灵感日志
- Để không có ký tự tiếng việt ở url wordpress (Nicer permalinks for Vietnamese) | Script Online Collection - Free nulled script - Clone sites
- WordPress Pretty Permalinks on IIS | danlefeb.com
- 使用wordpress的固定连接 | Just For Lee
- 《创想曲》电子杂志
- 01博客 » 修改固定链接说明
- WordPress 固定链接设置方式 | 诺哥
- 使用WordPress固定链接 « Escope
- 使用WordPress固定链接 – 对比----想象
- Why Use WordPress on Windows Server 2003?
- 使用固定链接 | Citi
- Remove Wordpress Index.php on Windows Servers | No Joke Guide
- windows+IIS下完美设置wordpress伪静态 - 文文策划
- 【转】WordPress固定链接的设置方法 | 田园牧歌
- 10 Steps to Making Wordpress Permalinks Work on Windows IIS 6.0 – Web Coach Pete SEO Blog
- 使用WordPress固定链接 « KingChine
- 使用WordPress固定链接 - 来自深圳SEO QQ61149538 - 外贸SEO-B2C网站优化-专注SEO数据、SEO工具、SEO外链资源等
- Wordpress使用固定链接及出现问题解决办法
- 使用WordPress固定链接 | 钥匙博客
- jcamweb's blog » El blog en iis 6.0 como ejecutable cgi (parte 2)
- win系统IIS6.0情况下|去掉固定链接中的index.php | 爱睿智.com|睿之iruizhi.com
- Day Two of WordPress uh…. pressure…. | What if?
- URL Rewriting with WordPress — Visual Basic Feng Shui
- 使用WordPress固定链接 | AngKaKa | 分享我所知道的···
- wordpress使用固定链接 « 运维之路
- Pretty Permalinks, Wordpress, and EasyCGI | ChadCardwell.net
- wordpress 中进行伪静态设置的官方简体中文文档 « zhuohang
- nojokeguide.com » Remove Wordpress Index.php on Windows Servers
- wordpress使用固定鏈接 - ORZ部落閣
- 帮一把? | 帮一把
- wordpress:使用固定链接 | 快乐不快乐
- WordPress伪静态的实现 | 阿辉博客
- win主机下WP固定链接(伪静态)实现方法全攻略 | 阿辉博客
- wordpress固定连接设置 | 无忧建站|网站建设|网站推广|
- WordPress固定链接设置 | HHDZL
- 如何设置固定链接?WordPress固定链接的设置方法 - 中文吧
- 使用 WordPress 的固定链接 - Xu Design
- 使用固定链接
- WordPress固定链接的设置方法 | 梦之翼'Blog
- Test10000中文显示价格区_全球优选
- WordPress固定链接的设置方法 让Nginx支持WordPress的固定链接 | 新的网
- wordpress后台使用固定链接的方法 | 龚磊博客
- IIS服务器解决伪静态固定链接的一种完美解决方案 | 绝妙网
You are an absolute genius. This seems to be the only thing that worked for me.
However, the only problem I’m having is that the Flash application I have on my homepage stops working. Why do you think it does this, and how do I fix it?
Thanks for this solution! Is there a way for actual 404s to redirect to a page using the 404.php template in my theme directory? Currently invalid URLs that would normally return a 404 show up blank.
You are a lifesaver, I used this for a client that had Windows Hosting and insisted on a wordpress website design. The permalink structure for it was horrible and I know would ruin his search engine optimization strategy of having nice links. Thanks again for this great tutorial!
it is very helpfull!thanks
very helpful and useful with me, thanks for tip !
Dan
This worked a treat. I had no idea that WordPress could work on a Windows machine.
Won’t this cause all pages pages deeper than the homepage to return a 404 status?
This would be horrible from an SEO perspective!
Please advise.
Awesome dude!!!!
omg thank you! I couldn’t get permalinks working for my new landing pages – found out it’s on IIS6
The code is work on my site, but there is a problem with the feed http://www.crusherinc.com/News/feed
How to solve it?
I did everything like the article says, but still, after changing the perrmalinks configuration, and setting the wp-404-handler file, I am getting the “page not found” error.
In Windows Server 2000 (IIS 5) running PHP 5, I was seeing the following message: “PHP Notice: Undefined index: ORIG_PATH_TRANSLATED in wp-404-handler.php on line 11″.
I modified line 11 to:
$_SERVER['PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['PATH_TRANSLATED']);
and that seems to have fixed the error.
In other words, change ORIG_PATH_TRANSLATED to PATH_TRANSLATED.
it is very helpfull, Thanks
While there are actually many details of tree services which unfortunately I want to
study, I appreciate that which you have outlined in this article,
URL Mod-Rewrite Workaround for IIS 6.0 and WordPress | ikailo, as it truly helps me get
a deeper understanding.
I was able to resolve the issue with your suggested changes. Great work!!
OS: Windows 2003
WordPress: 3.5
I have used the method given in below blog link and this also worked like a charm.
http://www.zappmania.in/index.php/2013/03/27/getting-wordpress-pretty-permalinks-working-on-iis-windows-hosting/
I do agree with all of the ideas you’ve introduced for your post. They are very convincing and can certainly work. Nonetheless, the posts are too brief for newbies. May you please lengthen them a little from next time? Thanks for the post.
Good info. Lucky me I came across your blog
by chance (stumbleupon). I have bookmarked it for later!