Tag Archive | "Wordpress permalinks"

Tags:

WordPress Permalinks On Windows


As we discussed on this wordpress permalinks configuration there’re several methods to configure friendly URLs for wordpress site. Here’re some issues I would like to discuss.

On windows server 2008 with URL rewrite mode configured environment, you can enable permalinks the same as you did from linux server and it will auto generate the URL rewrite rules from web.config in your website root. The content is the following:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
      <rules>
        <rule name="wordpress" patternSyntax="Wildcard">
          <match url="*"/>
          <conditions>
            <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>

However, if you installed wordpress on both website root and a subfolder of your website and would like to enable permalinks for both, it will give your 500 error about web.config configurations. Here you need to edit the web.config in the subfolder and add "<remove name="wordpress"/>" behind the <rules>

Now the permalinks would be working like a charm!

Sometimes you would like to redirect the 404 error pages to your home page or any other page on your website to avoid negative effect on search engine. you can do as steps below

Locate to your wordpress theme folder and create a 404.php page and paste into the following:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo(‘url’));

exit();

?>

Now, whenever you browse some non-exist pages on your wordpress site, it will be redirected to your website home, you can also specify where you like the page be redirected to from the second line, for example I would like to redirect to google.com, then you can edit like this:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.google.com");

exit();

?>

As you see, it’s pretty easy :)

Share

Posted in Windows-IIS-ASPNET, WordpressComments (0)

Tags:

WordPress Permalinks Configuration


It’s reasonable for your to make your website links/urls clean for SEO consideration, wordpress provided the great ideas from admin panel. If you’re using Apache web server, you don’t need it, you can simply define it directly from your wordpress admin page > settings > permalinks. This solution is for IIS, you need to define custom 404 error pages(including 404, 404,2 and 404,3). Put the following to a file called 404.php under your wordpress maine working directory:

<?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.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);
?>

Now you’ll be able to configure the permalinks in the way you liked.

Share

Posted in WordpressComments (14)