WordPress Permalink structure is important with respect to the Search Engine Optimization (SEO). I observed that most of the WordPress blogs have a Permalink Structure which looks like /index.php/%postname%/
. This post will help you to change your permalink structure using the Microsoft IIS 6 server.
- Create a “php” file, say ‘404_wp.php’, paste the below code and upload it to your wordpress root folder (i.e., in same folder/directory where “wp-config.php” file is located.
- Download and Install Internet Information Services (IIS) 6.0 Manager for Windows XP from Microsoft Site. Alternatively, you can install this from your Windows XP Installation CD.
Download Link - Go to your Windows Control Panel -> Administrative Tools and open Internet Information Services (IIS6) Manager
- Right click Internet Information Services and select Connect
- “Connect to Computer” dialog box will open, enter your IIS 6 Server IP Address, and Login Credentials
(In case, you can’t find the IP Address, you can open Command Prompt from Start Menu and ping your site to find IP Address) i.e. ping wpveda.com - Click OK, so as to connect to your server. The IIS manager will open as shown below.
- On left-hand side navigation, click on [+] before Your Server’s IP Address to expand
- Click on [+] to expand Web Sites
- Right click the name of website on which pretty permalinks need to be enable, and select Properties, which would open the Properties dialog box.
- Select Custom Error tabs, and find 404 from the grid.
- Click Edit button, you will be greeted by another dialog box. Select “URL” from Message Type Drop-Down, and for URL field, write relative path to “404_wp.php” file, that you have created and uploaded on your server (in step 1) and click OK.
- You can see the new “404” URL in Custom-Error Tab Grid. Close the dialog-box.
- Right click the web-site that you have connected to and select Disconnect and then close the Internet Information Services (IIS6) Manager
- Login to your WordPress Admin-Panel and change your permalink structure to /%postname%/ or any other structure as shown below.
<?php
// Default file for WordPress site, generally "index.php"
$wpdefault = 'index.php';
// The name of this file.
$tempfile = '404_wp.php';
$_SERVER['SCRIPT_FILENAME'] = str_replace($tempfile, $wpdefault, $_SERVER['SCRIPT_FILENAME']);
$_SERVER['ORIG_PATH_INFO'] = str_replace($tempfile, $wpdefault, $_SERVER['ORIG_PATH_INFO']);
$_SERVER['SCRIPT_NAME'] = str_replace($tempfile, $wpdefault, $_SERVER['SCRIPT_NAME']);
$_SERVER['PHP_SELF'] = str_replace($tempfile, $wpdefault, $_SERVER['PHP_SELF']);
$_SERVER['PATH_INFO'] = false;
$querystr =& $_SERVER['QUERY_STRING']; $requesturl =& $_SERVER['REQUEST_URI'];
$position = strrpos($querystr, '://');
$position = strpos($querystr, '/', $position + 4);
$_SERVER['URL'] = $requesturl = substr($querystr, $position);
$querystr = trim(stristr($requesturl, '?'), '?');
// Required for WordPress 2.8+
$_SERVER['HTTP_X_ORIGINAL_URL'] = $requesturl;
// Fix GET vars
foreach ( $_GET as $var => $val ) {
if ( substr($var, 0, 3) == '404') {
if ( strstr($var, '?') ) {
$nv = substr($var, strpos($var, '?') + 1);
$_GET[$nv] = $val;
}
unset($_GET[$var]);
}
break;
include($wpdefault);
?>
This is how you can easily change your permalink structure using the Microsoft IIS server for a good SEO for your blog. Do write your feedback through your comments.
21 Comments
I try to do everything you said but still not work with my web site
You have any idea to help me fix permalink problem with out index.php
Please tell me step by step I use window server IIS6 PHP 5.2.13 wordpress version 3.1
Thank you
Please cross check in WordPress admin section under Settings->General, if there is index.php URL is present then remove that. Hope it may help you.
WordPress address (URL) : http://cortestravel.com/wordpress
Site address (URL): http://cortestravel.com/wordpress
I look already don’t have index.php only have wordpress so how i can do now if you can help me more thank you for reply
You need to write some php code into index.php of your WordPress root. str_replace() function to replace the current URL of that is in browser with index.php URL.
I am not sure without looking into your WordPress files and hosting server , but hope the below code will work fine. Add this code in index.php
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}
function selfURL(){
if(!isset($_SERVER['REQUEST_URI'])){
$serverrequri = $_SERVER['PHP_SELF'];
}else{
$serverrequri = $_SERVER['REQUEST_URI'];
}
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$serverrequri;
}
$current_url = selfURL();
if (strstr($current_url, '/index.php/')) {
$current_url = str_replace('/index.php','',$current_url);
header('location:'.$current_url,TRUE,301);
}
Hi..Thank you for reply I put your code on my index.php already after that i go to change my permalink but still show 404 error not found,I use window 2003 IIS 6 PHP 5.2.13 wordpress version 3.1 VPS plan Plesk Panel ixwebhosting I don’t know what to do because they not have mod_rewrite and not accept 3 party software but i have ASP.NET Configuration for Domain you think i will setting something on ASP.net or not? I don’t know Please help.
Some assumptions :
1) Hope you added above given code in comment into index.php file, just above the previous code that already present in index.php.
2) you have already created 404 file says 404_wp.php file and now following all the steps as mentioned in this post.
If these above points are correctly done by you then it should work for your blog. I cannot suggest you exact solution, without looking into your server. You can avail our services to solve the above problem. Contact us https://bloggertowp.org/contact
Hey,
when I enable permalinks, some post links work, others don’t. will your post/ solution fix this?
Thx
Yes,
But I cannot see any index.php in your blog post permalink, and most of the links are working fine, so where you are getting problem?
Hi
my website http://expresssanantonio.news-locally.com
here on my permalinks section permakinks example displays http://expresssanantonio.news-locally.com/index.php/archives/123
this type of link.
I move my content from a site to this site.
Now my problem is if i want use this type of permalink http://expresssanantonio.news-locally.com/about-us
its not working. but http://expresssanantonio.news-locally.com/index.php/about-us is woking.
How ca i do that in IIS 6 Server
Hi Shalf,
This post is showing how to remove index.php section from permalink structure, you need to follow all the steps given in this post. And it will work fine.
Thanks,
No, its not working, I have confusion about the URL path. I set it /404_wp.php
the file is in root directory. You check my site.
http://expresssanantonio.news-locally.com/about-us/
http://expresssanantonio.news-locally.com/index.php/about-us/
Hi Shaifuddin, I believe that you need to add a few lines of code to ‘index.php’ file located in root directory.
Code is here http://wpveda.com/change-permalink-structure-iis-6-server/#comment-6859
Code basically handles all those requests, whose URL have index.php/something to /something
Thanks,
-Nitun
Hi, thank you for your greate tutorial. But i have a problem with it.
Parse error: syntax error, unexpected $end in C:Inetpubvhostsdomainhttpdocsblog404_wp.php on line 29
Hi Leton,
Please cross check, is there any extra line before / after closing tag of php code(?>) ?
Thanks
You got a bug. Missin “}”. I put it after the break;
i used the above code and it is working fine for inner pages, but not for home page. means http://www.mp3songsbox.co.in showing blank page
i am using windows 2003 shared hosting on IIS 6
No need to install any ISAPI filter to remove the index.php from WordPress permalinks.No need of .htaccess file..Use these simple steps to WordPress Permalinks in IIS 6.0 using Custom 404 Redirect for Windows Shared hosting/manas hosting or any windows shared hosting.
dotnetcodebytes.blogspot.com/2011/11/remove-indexphp-from-wordpress-on.html
Thanks Mukesh for your tips. 🙂
I am getting this error in 404 page. (pro) is my blog directory.
Parse error: syntax error, unexpected $end in C:\Sites\webroot\pro\404_wp.php on line 57
I put a bracket after break in last lines and now it is working with another error.
Warning: strpos() [function.strpos]: Offset not contained in string in C:\Sites\webroot\pro\404_wp.php on line 26