=== Plugin Name ===
Tags: iis, redirect, 301, 404, permalink, wp_rewrite_rules, isapi, isapi_rewrite, rewriterule, htaccess, mod_rewrite, seo, url, www
Requires at least: 2.0.0
Tested up to: 2.2
Stable tag: 0.2
Validates the URL used and if not matching the official permalink then it issues a HTTP 301 or HTTP 404 message.
== Description ==
Wordpress it very forgiving when supplying an URL that doesn't match the
actual permalink to a post or a page. This is caused by Wordpress using some
very greedy wp\_rewrite\_rules, which accepts almost any URL as valid.
For example it will accept the following permalink URL as valid:
> http://example.com/post/hello-world/2
Even though the official URL is this:
> http://example.com/post/hello-world/
Permalink Validator makes a hook to template_redirect, and then adds some
extra validation of the URL supplied before actually calling the
theme-templates.
This will also help Search Engine Optimization (SEO) as it prevents duplicate
contents on your Wordpress blog.
* 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/)).
* 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).
* Forces a correct 404 page instead of showing an empty search result when using an invalid URL.
* 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.
== Installation ==
1. Upload `permalink-validator.php` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
== Frequently Asked Questions ==
= Why should I use this instead of htaccess or isapi_rewrite ? =
If having the ability to use htaccess or isapi_rewrite, then one should continue
to use these to add missing trailing back-slash or www prefix. They are a lot
faster at redirecting than Permalink Validator, as they are activated without
starting the PHP script engine when the URL has incorrect format.
Permalink Validator extends the validation so besides checking the format,
then it also checks that the url is referring to something valid. The validation
of the url doesn't require any extra database queries besides those used
for displaying the page (unless the url requires redirection).
= Why does it redirect continously when activating the plugin ? =
The plugin makes a redirect when the url used to reach the page doesn't match the expected permalink url.
Some times this leads to an endless loop, which Firefox shows as:
> The page isn't redirecting properly
>
> Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
>
> * This problem can sometimes be caused by disabling or refusing to accept cookies.
This can be caused by a conflict in the htaccess /isapi_rewrite redirection rules and the given permalink structure:
* If enforcing trailing back-slash and the permalink structure doesn't include it.
If this is not the case then you are very welcome to post a topic with your problem as feedback to this plugin.
Please include your permalink-structure and Wordpress version in your description of the problem.
= How to block search engines from spidering Wordpress feed and trackback ? =
Add the following lines to your [robots.txt](http://www.robotstxt.org/):
> Disallow: \*/feed
> Disallow: \*/atom
> Disallow: \*/rss2
> Disallow: \*/rss
> Disallow: \*/trackback
> Disallow: /\*/feed
> Disallow: /\*/atom
> Disallow: /\*/rss2
> Disallow: /\*/rss
> Disallow: /\*/trackback
= How to make proper permalink URL's in IIS ? =
Wordpress supports by default Apache htaccess and its mod_rewrite rules.
When using Wordpress on IIS then these will not work and one is limited
to this type of permalink:
> http://example.com/index.php/post/hello-world/
To remove the index.php, then one can either use the [custom 404 redirects](http://www.keyboardface.com/IIS-Permalinks/)
or [isapi_rewrite](http://www.basilv.com/psd/blog/2006/running-wordpress-20-under-iis).
If using isapi_rewrite and changing from using index.php to not using index.php,
then one can use the following httpd.ini (Assumes Wordpress is installed in the root):
>[ISAPI_Rewrite]
>\# Rules to ensure that normal content gets through
>RewriteRule /software-files/(.\*) /software-files/$1 [L]
>RewriteRule /images/(.\*) /images/$1 [L]
>RewriteRule /favicon.ico /favicon.ico [L]
>RewriteRule /robots.txt /robots.txt [L]
>
>\# For file-based wordpress content (i.e. theme), admin, etc.
>RewriteRule /wp-(.\*) /wp-$1 [L]
>
>\# Rule to perform 301 redirect to ensure trailing back-slash on post and pages
>RewriteCond Host: (.\*)
>RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,R]
>
>\# Rule to perform 301 redirect (Remove index.php if specified)
>RewriteRule /index.php/(.\*) /$1 [I,RP]
>
>\# For normal wordpress content, via index.php
>RewriteRule ^/$ /index.php [L]
>RewriteRule /(.\*) /index.php/$1 [L]
= Why is there no redirection when supplying index.php on IIS ? =
Permalink Validator cannot see the difference between this url:
> http://example.com/post/hello-world/
And this url on IIS:
> http://example.com/index.php/post/hello-world/
This is because REQUEST\_URI is not supported properly on IIS, so it is
impossible to know whether index.php was specified or not. The solution
is to use isapi_rewrite to specify a rule so it performs 301 redirect
when using the url containing index.php (See example above).
= Will Google tracking code work with this plugin ? =
Google tracking code adds a question-mark (?) option to the URL, which the
Permalink Validator will strip because it is not part of the permalink URL.
Instead of using a question-mark (?), then one could use a hash (#) value,
and then modify the Google tracking code to extract the hash value
instead of the question-mark value.
== Version History ==
Version 0.2
* Added support for static front page.
* Added detection of integrated [BBPress](http://bbpress.org/).
* Checks that Wordpress has been started before adding hooks
Version 0.1
* Fixes REQUEST_URI for WP on IIS, which also fixes pagination.
* Handles permalink structure with or without index.php.
* Handles default permalink structure using only post-id.
== Contributors ==
* [Scott Yang](http://fucoder.com/code/permalink-redirect/) for giving me the idea and the example of to how make this plugin.
* [Gabe Anderson](http://www.articulate.com/blog/) for giving me the initiative to release this plugin.