Moved!
I have moved this project to my new programming/Internet blog — Permalink Redirect WordPress plugin.
About
I am not sure why the WordPress people insist that,
GET /2005/05/29/foo-bar HTTP/1.1
is exactly the same as
GET /2005/05/29/foo-bar/ HTTP/1.1
If you have not spotted the difference, one has a trailing forward slash ‘/’ in the URI and one does not. For one is requesting the content of object ‘foo-bar’ under directory ‘/2005/05/29/’, and another one is requesting the content of the index file under directory ‘/2005/05/29/foo-bar/’. Although many of us would usually ignore the trailing slash, and write out the URL without it, web servers usually will correct this behaviour by replying a 301 permanent redirect to an URL with the trailing slash, if ‘foo-bar’ is indeed a directory.
However, not so with the default mod_rewrite rules generated by WordPress. To save number of rules need to be generated, WordPress short-cuts the regular expression to allow optional trailing slashes at the end of the URL. This results that you can now point to the same entry/archive with or without the trailing slash – which goes against what a search engine would recommend. Here is an extract of Google’s recommendation to the webmasters, under “Quality Guidelines – Specific recommendations”:
Don’t create multiple pages, subdomains, or domains with substantially duplicate content.
Now if I search Google for certain keywords, I sometimes see two results came back from the same domain – same blog entry but one with a trailing slash in its URL, and one does not. For example, mtsend. This is certainly not what I have desired. I used to modify all the mod_rewrite rules generated by WordPress, so that Apache will issue a 301 redirect if the trailing space is missing. However, it is tedious, and not compatible when WordPress upgrades. Moreover, your .htaccess becomes huge and getting unmaintainable.
Therefore, this simple WordPress 1.5+ plugin is written. It compares the request URI, and if it does not match the permalink, a redirect will be sent back instead. It works not only for individual blog entries, but also yearly/monthly/daily and category archives, so that there is always only be one URL for each of your blog entries and archives.
Interestingly, if you check out the URIs generated by WordPress through a ‘standard’ site, you should notice that all the URIs do in fact have a trailing slash on them.
I’d begin to wonder how the results for mtsend have multiple entries. I initially thought, it might have been caused by people linking to that article with and without the trailing slash, which would/might cause two entries in the Google index. However, if you use a link: to the URI without a trailing slash, it returns no results.
Do you have any thoughts how you’d get multiple entries?
Al.
That’s a possibility – there might be someone who linked the entry without the trailing slash. Googlebot followed the link, and subsequently indexed the same entry again with two totally different URL’s. But I guess my point is, WordPress should handle this situation by doing a redirect to the correct permalink, instead of just serve the content. Googlebot would be happy to take a 301 and follow to the new location.
I’ll see whether that entry goes away from Google’s index when they update the next time.
You should put this in the plugin directory.
That is in fact just one example: this plugin will also redirect stuff like
http://yourblog.ext/?p=123to the correct permalink IRI. Thanks for this kick-ass piece of coding, I hope it will get into the core soon.I want try this one.
Thanks for nice plugin
(off topic : I noticed that there is something weird with something I identify as my IP 2 Nation plugin. The first flag in comments has an alt tag with “from France”, which is my country, and then every flag has the alt tag of its predecessor one. Weird heh :)
Looks awesome! Great job!
Pingback: One Permalink Only [ Tempus Fugit | TxFx.net ]
Ozh,
Thanks for the spotting! It is indeed a typo in my template. Fixed now.
Everyone,
Thanks for the comments. I’ll try to get that registered as a WordPress plugin today.
Pingback: idleMind.org Journal
Ohboyohboyohboy this is going to simplify BOTD coding when it gets into the core. You rock.
I have just one question.
Does it modify /foo-bar and make it /foo-bar/ or does it take /foo-bar/ and make it /foo-bar ??
I mean does it add or remove the slash?
If such a system is used could it solve this problem of mine?
Ajay,
It shall redirect to whatever the permalink is supposed to be, with or without the trailing ‘/’. However, I don’t think it would work if your permalink config does not have the final ‘/’, but then someone request it with one, as I only check whether the permalink is a substring of the request URI, in case there are other things appending to it (/page/, /feed/, etc)
You ROCK!
This is exactly what I’ve been looking for! Well done!
Thanks for the plugin, I too find it important to redirect people to the proper canonical URL.
As far as I figured out, then it doesn’t treat URLs to pages, only to posts. Could it be updated to handle pages too?
Pingback: Martin Geisler Online
Very nice! This fixes a problem that was bugging me last week when I discovered pingbacks had stopped using the permalink structure. It was just an upgrade snafu, fixed easily, but I had left a week or two of pingbacks scattered around the web with an ugly/redundant index.php?p=xyz link. (Not to mention all the duplicate links from people leaving out the trailing slash.)
Awesome plugin, thanks Scott!
Tried installing using 1Click install. I get this error:
When I activate your plugin, the JÄÅ Preview plugin stops working.
The JÄÅ Preview plugin launches a new browser window with an URL of this type: [blog URL]/?name=preview&idpost=[post ID]. However, if your plugin is activated, the browser is redirected to an URL like this: [blog URL]/archives/[year]/[month]/[day]//. Would you care to check this out, I’ve looked at the code of both your plugin and JÄÅ Preview but even though it looks simple I have no experience in writing WordPress plugins.
Ajay,
I have not tried 1click install yet – might have a look later.
Paulo,
As far as I can see, the preview plugin does nothing but loads the specific post from database and display in the a separate window – which is exactly the same as loading the post from its permalink! Even though permalinks redirect plugin will alter the final URL, I don’t see how it has stopped the prview plugin from working.
Hello,
I found it can not convert something like “/?m=200504″, it should be “/2005/04″ but it always turns to be “/2005/06″ (current month).
I looked a bit further into the problem and I discovered that it had nothing to do with your plugin! :) It was the fact that the post slug was missing that prevented the URL from loading (hence the empty space between the slashes at the end of the address).
Congratulations for your plugin, it’s really useful.
:oops: I missed the trailing slash at comment 23,“/2005/04/″and “/2005/06/″.
Very nice!
It’s not working entirely for me though.
Could it be that I purposefully do not have trailing slashes on my site? That is, My permalinks are /%year%/%month%/%postname% and not /%year%/%month%/%postname%/
Mark,
The ‘?m=yyyymm’ syntax is not supported, but it should be trivial to add that by looking at how WP_Query is constructed. I’ll look at that tomorrow (need to head to bed soon). Nice blogsite, btw :)
Joen, I have the same permalink structure as you do, and (that part of) the plugin works perfectly on my blog.
I am having that problem too though, but then with category permalinks. Those look like this on my site:
http://mathibus.com/archive/topics/php(note the lack of a trailing slash, which is intended). Your plugin seems to redirect that kind of stuff tohttp://mathibus.com/archive/topics/php/(with the trailing slash). The thing is, I have mod_rewrite rules in my .htaccess that redirects IRIs that end with a trailing slash (unless the requested file is a directory, of course) to the same IRI without the slash… Which makes your plugin conflict with my .htaccess and thus cause a redirection loop. Any ideas on how to fix this?Pingback: SteelPixel
Pingback: SteelPixel » Blog Archive » Hacking the Permalink Redirect Wordpress Plugin
Great plugin. Thanks.
If your permalink does not contain a trailing slash, then in the case when a trailing slash has been appended to the REQUEST URI, it should either
1. process the link without redirect, and treat the trailing slash as PATH_INFO, or
2. issue a 404 Not Found.
I am more in favour of (2) – just try that on any static file and a web server would give you back a 404.
Actually Scotty, I can see a Permalink Redirect plugin available. Did you add it to wp-plugins.net?
Also, check out steelpixel’s hack to include pages as well :)
I think I may have found a small bug. If you make any alteration to the post slug in the URL (while this plugin is active), the custom 404 page is not loaded. Instead, you’re either taken back to the main page of the blog, or taken to a blank page.
Pingback: MacManX.com » Blog Archive » Active Plugins
Hmmm, just the ticket… more or less. :D
Pingback: unFocus » permalinks on IIS
Scott: I’m trying to figure out whether your plugin will solve a really thorny technical problem I’m having. I migrated my blog from typepad to wp retaining the same domain name richardsilvertein.com. But typepad permalinks have this format: http://www.richardsilvertein.com/tikun_olam/yr/mo/day/i_have_a.html format. Many people are using old format hyperlinks to get to the same posts but in my new blog (via search engines, links in other people’s blogs, etc.). Since I’m using the same domain for my WP blog, they ARE getting to my new blog site. But I can’t figure out a way to use mod_redirect/htaccess to convert those old links into WP’s http://www.richardsilverstein.com/tikun_olam/yr/mo/day/i-have-a/ format (which is the path structure I’m currently using) so that they can not only get to my new site, but to the specific post they’re seeking.
Is there a way your plugin will do this?
ANother ?: when I click your download link I don’t get an actual download. My FF browser merely opens the file in a new browser screen & I see the code. How do I download it?
Richard,
FF – Right click and “Save Link as”…
And you can set your permalink structure like the way TypePad has set up. Go to the Permalinks section under “Options” of WP admin, and use:
/tikun_olam/%year%/%monthnum%/%day%/%postname%.html
as permalinks structure. You’ll need to use the following plugin to use underscores instead of hyphens in permalinks.
http://codex.wordpress.org/Plugins/Underscore_Permalinks
Hello scotty,
Another format that does not redirect by the plugin (0.3)
/index.php?paged=3
will not redirect as
/page/3/
Will you add this? Thanks.
Pingback: The making of this blog – verbage.net
Hey guys,
A little late here, but, I found an .htaccess file that adds the trailing slash automatically. I initially searched for this because yahoo automatically strips the trailing slash. :(
http://wordpress.org/support/topic/38441
Scott – any chance this script could be modified to handle Typepad’s truncation? Typepad truncates titles to 15 characters and then ads a numeral for dupes. I.e. the first instance of a URL could be:
…/example_of_post
and then a second post with an identical first 15 characters would be,
…/example_of_post_1
I want to migrate to WordPress but have to find a way to maintain my URL’s. Unlike Movable Type, Typepad doesn’t give the option to keep long page names intact.
Pingback: mein Weblog und seine Plugins
Pingback: GeekFun » Blog Archive » From Movable Type to Wordpress
Pingback: Tabakblog » Blog Archive » Weitere Wordpress-Plugins installiert
Pingback: Permalink Redirect WordPress Plugin 0.4 | FuCoder.com
Pingback: SEO Plugins Wordpress 1.5.2 - SEO Marketing Blog
Pingback: A Guide to an SE Optimized Wordpress Setup » @ Ambot ah! [ technology news and reviews ]
Pingback: Weblog-Optimierung f
I came here from a google search for wordpress permalinks. I wanted to know how wordpress ensures that two blog with the same titles have different permalinks? Any ideas?
Pingback: Los Blog’s de la pagina de UiDoS » Plugins para WordPress
Pingback: SEO Plugins für WordPress - BeNatix.com
Hey mate, thanks for the Permalink Redirect WordPress plugin. Verry usefull 4 me. John :-)
Pingback: SEO para Wordpress
Pingback: 睡觉的眼皮
Pingback: 282 plugins para WordPress (4ª parte de la L a la Q) | Pichicola.com
Pingback: Inspirit Blog switches from Windows based host to Linux based host
Awesome plugin, thanks Scott!!
Pingback: Plugins Para WordPress | Mega Post
Thanks, very good plugin. I am searching exactly for such a plugin :)
Pingback: Inicio « mediasur.cl
Pingback: Plugins para Wordpress. | Puydi Publicidad 100% efectiva
Pingback: webmaster esmuy.com » Blog Archive » Plugins para Wordpress
Pingback: Gran colección de plugins Wordpress -- Mundo Inteligente
Pingback: Plugins para wordpress | UrbanBlog
Pingback: Oloroko Blog – Lista de Plugins para Wordpress
Pingback: Descargar Plugins para Wordpress | ZonaFull.Org
Pingback: Plugins para Wordpress «
My original url was
http://biblicalgeology.net/blog/archives/527
I installed the plug in.
I changed the settings on the WP permalinks settings.
I edited the permalink on each blog entry to make it shorter and neater.
The url now is: http://biblicalgeology.net/blog/the-blowhole-kiama/
When I put the original url in the browser I get a 404 error.
“Oops! The page you’re looking for can’t be found. Search biblicalgeology.net:
blog archives 527″
Can anyone help me fix it? Thanks