[44] | 1 | === Plugin Name ===
|
---|
| 2 | Tags: iis, redirect, 301, 404, permalink, wp_rewrite_rules, isapi, isapi_rewrite, rewriterule, htaccess, mod_rewrite, seo, url, www, canonical
|
---|
| 3 | Requires at least: 2.0.0
|
---|
| 4 | Tested up to: 2.6
|
---|
| 5 | Stable tag: 0.8
|
---|
| 6 |
|
---|
| 7 | Validates the URL used and if not matching the official permalink then it issues a HTTP 301 or HTTP 404 message.
|
---|
| 8 |
|
---|
| 9 | == Description ==
|
---|
| 10 |
|
---|
| 11 | Wordpress 2.3 now includes validation of the permalink URL when using Apache web server,
|
---|
| 12 | but if using IIS then this plugin is still relevant.
|
---|
| 13 |
|
---|
| 14 | Permalink Validator helps Search Engine Optimization (SEO) as it prevents duplicate
|
---|
| 15 | contents on your Wordpress blog:
|
---|
| 16 |
|
---|
| 17 | * Adds trailing back-slash if missing (Can also be done with [htaccess](http://www.alistercameron.com/2007/01/12/two-wordpress-plugins-you-dont-need-and-shouldnt-use/) or [isapi_rewrite](http://cephas.net/blog/2005/07/11/trailing-slashes-iis-and-f5-big-ip/)).
|
---|
| 18 | * Adds or removes www prefix according to your permalink structure (Can also be done with [htaccess](http://andybeard.eu/2007/04/the-ultimate-wordpress-htaccess-file.html) or isapi_rewrite).
|
---|
| 19 | * Forces a correct 404 page instead of showing an empty search result when using an invalid URL
|
---|
| 20 | * Works only on post, pages and categories. Archives based on date (Daily, Monthly, Yearly) and search-result-pages should use noindex. Feed and trackback pages should be added to the robots.txt.
|
---|
| 21 | * Fixes pagination for WP on IIS.
|
---|
| 22 | * Fixes trailing slash for pages and categories on WP 2.2 when not having trailing slash in post permalink structure.
|
---|
| 23 |
|
---|
| 24 | Wordpress it very forgiving when supplying an URL that doesn't match the
|
---|
| 25 | actual permalink to a post or a page. This is caused by Wordpress using some
|
---|
| 26 | very greedy wp\_rewrite\_rules, which accepts almost any URL as valid.
|
---|
| 27 |
|
---|
| 28 | This means that multiple URLs could be used to reach the page, which search engines
|
---|
| 29 | sees a duplicate content and leads to penalty.
|
---|
| 30 |
|
---|
| 31 | For example it will accept the following permalink URL as valid:
|
---|
| 32 |
|
---|
| 33 | > http://example.com/post/hello-world/2
|
---|
| 34 |
|
---|
| 35 | Even though the official URL is this:
|
---|
| 36 |
|
---|
| 37 | > http://example.com/post/hello-world/
|
---|
| 38 |
|
---|
| 39 | Permalink Validator makes a hook to template_redirect, and then adds some
|
---|
| 40 | extra validation of the URL supplied before actually calling the
|
---|
| 41 | theme-templates.
|
---|
| 42 |
|
---|
| 43 | == Installation ==
|
---|
| 44 |
|
---|
| 45 | 1. Upload `permalink-validator.php` to the `/wp-content/plugins/` directory
|
---|
| 46 | 1. Activate the plugin through the 'Plugins' menu in WordPress
|
---|
| 47 |
|
---|
| 48 | == Frequently Asked Questions ==
|
---|
| 49 |
|
---|
| 50 | = Why should I use this instead of htaccess or isapi_rewrite ? =
|
---|
| 51 | If having the ability to use htaccess or isapi_rewrite, then one should continue
|
---|
| 52 | to use these to add missing trailing back-slash or www prefix. They are a lot
|
---|
| 53 | faster at redirecting than Permalink Validator, as they are activated without
|
---|
| 54 | starting the PHP script engine when the URL has incorrect format.
|
---|
| 55 |
|
---|
| 56 | Permalink Validator extends the validation so besides checking the format,
|
---|
| 57 | then it also checks that the url is referring to something valid. The validation
|
---|
| 58 | of the url doesn't generate any extra overhead in database queries (unless the url requires redirection).
|
---|
| 59 |
|
---|
| 60 | = Why does it redirect continously when activating the plugin ? =
|
---|
| 61 | The plugin makes a redirect when the url used to reach the page doesn't match the expected permalink url.
|
---|
| 62 | Some times this leads to an endless loop, which Firefox shows as:
|
---|
| 63 |
|
---|
| 64 | > The page isn't redirecting properly <br/>
|
---|
| 65 | > <br/>
|
---|
| 66 | > Firefox has detected that the server is redirecting the request for this address in a way that will never complete. <br/>
|
---|
| 67 | > * This problem can sometimes be caused by disabling or refusing to accept cookies. <br/>
|
---|
| 68 |
|
---|
| 69 | This can be caused by a conflict in the htaccess / isapi_rewrite redirection rules and the given permalink structure:
|
---|
| 70 |
|
---|
| 71 | * If enforcing trailing back-slash and the permalink structure doesn't include it.
|
---|
| 72 |
|
---|
| 73 | If this is not the case then you are very welcome to post a topic with your problem as feedback to this plugin.
|
---|
| 74 | Please include your permalink-structure and Wordpress version in your description of the problem.
|
---|
| 75 |
|
---|
| 76 | = How to exclude pages from being permalink validated ? =
|
---|
| 77 | The Permalink Validator will pretty much validate any URL you throw at it,
|
---|
| 78 | but sometimes there are URL's that should not be validated.
|
---|
| 79 |
|
---|
| 80 | Edit the plugin-code and replace this line:
|
---|
| 81 |
|
---|
| 82 | > $excludes = array();
|
---|
| 83 |
|
---|
| 84 | With an array of the URL's to ignore:
|
---|
| 85 |
|
---|
| 86 | > $excludes = array("/forum");
|
---|
| 87 |
|
---|
| 88 | Plugins that requires an URL excluded:
|
---|
| 89 |
|
---|
| 90 | * [Subscribe to Comments](http://wordpress.org/extend/plugins/subscribe-to-comments/) - Exclude "/?wp-subscription-manager"
|
---|
| 91 | * [wp-forum](http://wordpress.org/extend/plugins/wp-forum/) - Exclude "/forum"
|
---|
| 92 |
|
---|
| 93 | = How to block search engines from spidering Wordpress feed and trackback ? =
|
---|
| 94 | Add the following lines to your [robots.txt](http://www.robotstxt.org/):
|
---|
| 95 |
|
---|
| 96 | > Disallow: \*/feed <br/>
|
---|
| 97 | > Disallow: \*/atom <br/>
|
---|
| 98 | > Disallow: \*/rss2 <br/>
|
---|
| 99 | > Disallow: \*/rss <br/>
|
---|
| 100 | > Disallow: \*/trackback <br/>
|
---|
| 101 | > Disallow: /\*/feed <br/>
|
---|
| 102 | > Disallow: /\*/atom <br/>
|
---|
| 103 | > Disallow: /\*/rss2 <br/>
|
---|
| 104 | > Disallow: /\*/rss <br/>
|
---|
| 105 | > Disallow: /\*/trackback <br/>
|
---|
| 106 |
|
---|
| 107 | = How to make proper permalink URL's in IIS ? =
|
---|
| 108 | Wordpress supports by default Apache htaccess and its mod_rewrite rules.
|
---|
| 109 | When using Wordpress on IIS then these will not work and one is limited
|
---|
| 110 | to this type of permalink:
|
---|
| 111 |
|
---|
| 112 | > http://example.com/index.php/post/hello-world/
|
---|
| 113 |
|
---|
| 114 | To remove the index.php, then one can either use the [custom 404 redirects](http://www.keyboardface.com/IIS-Permalinks/)
|
---|
| 115 | or [isapi_rewrite](http://www.basilv.com/psd/blog/2006/running-wordpress-20-under-iis).
|
---|
| 116 |
|
---|
| 117 | If using isapi_rewrite and changing from using index.php to not using index.php,
|
---|
| 118 | then one can use the following httpd.ini (Assumes Wordpress is installed in the root):
|
---|
| 119 |
|
---|
| 120 | >[ISAPI_Rewrite]<br/>
|
---|
| 121 | >\# Rules to ensure that normal content gets through <br/>
|
---|
| 122 | >RewriteRule /software-files/(.\*) /software-files/$1 [L] <br/>
|
---|
| 123 | >RewriteRule /images/(.\*) /images/$1 [L] <br/>
|
---|
| 124 | >RewriteRule /favicon.ico /favicon.ico [L] <br/>
|
---|
| 125 | >RewriteRule /robots.txt /robots.txt [L] <br/>
|
---|
| 126 | >
|
---|
| 127 | >\# For file-based wordpress content (i.e. theme), admin, etc. <br/>
|
---|
| 128 | >RewriteRule /wp-(.\*) /wp-$1 [L] <br/>
|
---|
| 129 | >
|
---|
| 130 | >\# Rule to perform 301 redirect to ensure trailing back-slash on post and pages <br/>
|
---|
| 131 | >RewriteCond Host: (.\*) <br/>
|
---|
| 132 | >RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,R] <br/>
|
---|
| 133 | >
|
---|
| 134 | >\# Rule to perform 301 redirect (Remove index.php if specified) <br/>
|
---|
| 135 | >RewriteRule /index.php/(.\*) /$1 [I,RP] <br/>
|
---|
| 136 | >
|
---|
| 137 | >\# For normal wordpress content, via index.php <br/>
|
---|
| 138 | >RewriteRule ^/$ /index.php [L] <br/>
|
---|
| 139 | >RewriteRule /(.\*) /index.php/$1 [L] <br/>
|
---|
| 140 |
|
---|
| 141 | = Why doesn't it redirect on IIS when the URL is wrong ? =
|
---|
| 142 | Permalink Validator cannot see the difference between this url:
|
---|
| 143 |
|
---|
| 144 | > http://example.com/
|
---|
| 145 |
|
---|
| 146 | And this url on IIS:
|
---|
| 147 |
|
---|
| 148 | > http://example.com/index.php
|
---|
| 149 |
|
---|
| 150 | It can also not see the difference between this url:
|
---|
| 151 |
|
---|
| 152 | > http://example.com/
|
---|
| 153 |
|
---|
| 154 | And this url on IIS:
|
---|
| 155 |
|
---|
| 156 | > http://example.com/////
|
---|
| 157 |
|
---|
| 158 | This is because REQUEST\_URI is not supported properly on IIS, and this
|
---|
| 159 | plugin can only simulate REQUEST\_URI to a certain limit. Therefore
|
---|
| 160 | it is impossible to know whether index.php or extra slashes was specified or not.
|
---|
| 161 | The solution is to use a rewrite engine like [ISAPI_rewrite](http://www.isapirewrite.com/)
|
---|
| 162 | or [IIS mod-rewrite](http://www.micronovae.com/) as they can provide a proper REQUEST\_URI.
|
---|
| 163 |
|
---|
| 164 | = Why does a non existing page give HTTP error 200 on IIS ? =
|
---|
| 165 | Microsoft IIS fails to reply with error code 404 in the HTTP header,
|
---|
| 166 | when trying to access an non existing Wordpress page. This usually happens
|
---|
| 167 | when using a custom 404 page on IIS.
|
---|
| 168 |
|
---|
| 169 | It seems that when using PHP on IIS, then it is not possible to reply
|
---|
| 170 | with a proper HTTP header. Apparently the only way to return a proper
|
---|
| 171 | 404 on IIS is to use ASP.
|
---|
| 172 |
|
---|
| 173 | = Will Google tracking code work with this plugin ? =
|
---|
| 174 | Google tracking code adds a question-mark (?) option to the URL, which the
|
---|
| 175 | Permalink Validator will strip because it is not part of the permalink URL.
|
---|
| 176 |
|
---|
| 177 | Instead of using a question-mark (?), then one could use a hash (#) value,
|
---|
| 178 | and then modify the Google tracking code to extract the hash value
|
---|
| 179 | instead of the question-mark value.
|
---|
| 180 |
|
---|
| 181 | == Version History ==
|
---|
| 182 | Version 0.8
|
---|
| 183 |
|
---|
| 184 | * Fixed PHP Warning: strpos() [function.strpos]: Empty delimiter
|
---|
| 185 | * Converted the PHP file from UTF8 to ANSI (Removed special BOM character in file beginning)
|
---|
| 186 |
|
---|
| 187 | Version 0.7
|
---|
| 188 |
|
---|
| 189 | * Permalink Validator will not perform redirect of POST server request
|
---|
| 190 |
|
---|
| 191 | Version 0.6
|
---|
| 192 |
|
---|
| 193 | * Fixed a redirection bug introduced in 0.5 when the front page is a page of posts
|
---|
| 194 |
|
---|
| 195 | Version 0.5
|
---|
| 196 |
|
---|
| 197 | * Wordpress 2.3 includes permalink validation (canonical urls) when using Apache, so this plugin should now only be used with IIS
|
---|
| 198 | * Added support for HTTPS urls
|
---|
| 199 | * Added support for special IIS installations where PATH_INFO and SCRIPT_NAME is the same
|
---|
| 200 | * Added small hack to exclude pages from validation (One is required to edit the source to use it)
|
---|
| 201 | * Added detection of the plugin [Jerome's Keywords](http://vapourtrails.ca/wp-keywords)
|
---|
| 202 |
|
---|
| 203 | Version 0.4
|
---|
| 204 |
|
---|
| 205 | * Better guessing of a proper REQUEST\_URI
|
---|
| 206 | * Finds the proper REQUEST\_URI when using isapi_rewrite
|
---|
| 207 | * Finds the proper REQUEST\_URI when using IIS Mod-Rewrite
|
---|
| 208 | * Improved validation as it nows expects a proper REQUEST_URI (Guess Apache is now supported)
|
---|
| 209 |
|
---|
| 210 | Version 0.3
|
---|
| 211 |
|
---|
| 212 | * Fixes trailing slash for pages and categories in WP 2.2 when using a post permalink structure without ending slash.
|
---|
| 213 |
|
---|
| 214 | Version 0.2
|
---|
| 215 |
|
---|
| 216 | * Added support for static front page.
|
---|
| 217 | * Added detection of integrated [BBPress](http://bbpress.org/).
|
---|
| 218 | * Checks that Wordpress has been started before adding hooks
|
---|
| 219 |
|
---|
| 220 | Version 0.1
|
---|
| 221 |
|
---|
| 222 | * Fixes REQUEST_URI for WP on IIS, which also fixes pagination.
|
---|
| 223 | * Handles permalink structure with or without index.php.
|
---|
| 224 | * Handles default permalink structure using only post-id.
|
---|
| 225 |
|
---|
| 226 | == Testing Procedures ==
|
---|
| 227 | For each of the different permalink structures:
|
---|
| 228 |
|
---|
| 229 | * Default permalink structure (Using query string)
|
---|
| 230 | * Permalink structure with index.php
|
---|
| 231 | * Permalink structure without index.php (Using ISAPI_rewrite)
|
---|
| 232 | * Permalink structure ending with .html
|
---|
| 233 | * All the above in a sub-directory
|
---|
| 234 |
|
---|
| 235 | Tries the following pages:
|
---|
| 236 |
|
---|
| 237 | * Front page and paged
|
---|
| 238 | * Static page
|
---|
| 239 | * Post page
|
---|
| 240 | * Category page and paged
|
---|
| 241 | * Front page as static page (WP 2.2+)
|
---|
| 242 | * Front page as post page (WP 2.2+)
|
---|
| 243 |
|
---|
| 244 | == Contributors ==
|
---|
| 245 | * [Scott Yang](http://fucoder.com/code/permalink-redirect/) for giving me the idea and the example of to how make this plugin.
|
---|
| 246 | * [Gabe Anderson](http://www.articulate.com/blog/) for giving me the initiative to release this plugin.
|
---|