Tag Archives: web server

Correcting Permalinks After Moving Content From A Subdirectory To Root

Ran into this problem with the blog:

As previously noted, I moved my WordPress install from a subdirectory to the root of my Web site. I tried the “Giving WordPress Its Own Directory” method, but I didn’t trust it, so I decided to go ahead with a physical move of the software to root.

As a result, all permalinks to the 200+ articles in this blog became broken, since the subdirectory /blog/ was part of the permanent path root. This was bad, because Google has all those old links wrong, and so does my YOURLS install.

So, I needed a fix, stat. Thankfully, Apache has the mod_alias module, which does a better job of rewriting URLs from subdirectories to root directory than mod_rewrite does.

I specifically used the RewritePermanent directive, which allows one to specify part of a URL string, and to where URLs containing that string should be directed. In my case, I wanted to direct all URLs that contained the  /blog/ subdirectory to the root of my site. Thus:

<IfModule mod_alias.c>
RedirectPermanent /blog/ http://www.dougv.com/
</IfModule>

The first argument after RedirectPermanent is the part of the URL you want removed. The second argument is the URL to which you want found URLs redirected.

This works far better for me than the handful of mod_rewrite rules I tried to accomplish the same basic task.

Your Web server must have mod_alias installed for this to work. Most shared Web hosts will have installed mod_alias, but some might not, or might only enable it for selected domains, as a lot of rewrites and aliases can cause trouble with search engine rankings. Check with your Web service provider.

A hat tip to julianmatz at experts-exchange.com for the tip. All links in this post on delicious: http://www.delicious.com/dougvdotcom/correcting-permalinks-after-moving-content-from-a-subdirectory-to-root

Web Site Changes: New Theme, New Root

As you can see, I have been working on this site’s theme.

I’m designing specifically to support the IAB Universal Ad Package. The way I’ve done that is through three columns: The left, “content,” column is 728 pixels wide,  which is the same as a leaderboard; the center column is 180 pixels wide, which supports both the rectangle and wide skyscraper formats; and the right column is 300 pixels wide, which supports the medium rectangle.

I remain committed to never having advertising on this site, nor ever charging for any content here. (I greatly appreciate donations, and I do charge for customizing / specific implementations of my code). The reason I am designing my site this way is to both have a base template from which to develop client sites that need to support advertising, and because the WordPress Codex is thin on templates specifically geared toward supporting display advertising.

Finally, I moved the blog from a subdirectory to the root of my Web server. When I started blogging with WordPress back in 2006, I thought I might do something else with the site, and didn’t want to clutter up the root with WordPress-specific rewrite rules and files. Since then, WordPress has become a much more robust content management system, and I’ve discovered that a blog is all I really need, so it’s high time everything went to the root.

As a result of all these changes:

  1. The template has some problems still, which I’ll be fixing over the next few days. If you spot a problem, please leave a comment.
  2. Many local links, namely download and image links, are likely broken; I will be fixing those, too, over the next few days.
  3. I’ve not installed WP-Syntax, my old code highlighting plugin, because I’ve gone completely over to SyntaxHighligher Evolved. Thus, some code may not wrap properly or look pretty, especially on older posts. You guessed it: I’ll fix that over the next few days.

Again, if you spot something that needs fixing, please let me know by leaving a comment to this post. Thanks!

Getting QueryString Values From A Rewritten URL / ASP.NET Routing URL

During today’s similcast of the ASP.NET Firestarter in Atlanta, G. Andrew Duthie discussed .NET 4′s new support for routing — or, what everyone in Web development calls “URL rewriting.” *

Someone online asked, “If I use routing, can I access query string variables using JavaScript?”

The question isn’t as confused as it sounds on the surface. Of course, if one uses routing / URL rewriting, it’s to remove query string variable and make them part of what appears to be a permanent file structure.

In other words, this:

http://www.server.com/path/to/file.aspx?v1=foo&v2=bar

Becomes this:

http://www.server.com/path/to/file/v1/foo/v2/bar/

The questioner really means, is there a way, after rewriting a URL, to extract key->value pairs from it via JavaScript? The answer is yes; rather than using the location.search property, which allows JavaScript to get the querystring parameters of a URL, we use location.pathname to get the part of the URL that follows the domain, and use that to create our key->value pairs.

Continue reading

Custom ErrorDocuments Available For Download

After writing so much about the ASP.NET cryptographic padding oracle exploit, and the recommended workaround of a static error document, it dawned on me that I should probably make some custom error documents for my domains.

And then I decided I should share them. So, if you’re so inclined, you can download the custom error documents I use on this site. I release all code under the latest version of the GNU GPL.

I’ve created pages for 401 (unauthorized), 403 (forbidden), 404 (not found) and 500 (internal server) HTTP errors.

I designed these to be valid XHTML 1.0; to appear well in all screen resolutions from 1024 x 768 and greater; and to appear the same on most Web browsers. (Of course, I exclude Internet Explorer prior to version 7 from that list.)

This little exercise also gave me a chance to play with the Google Font API. There aren’t a lot of fonts available yet, but using the API couldn’t be simpler.

Instructions on implementing custom error document on Apache can be found here. Microsoft documents how to add customError files to your ASP.NET web.config file here.

All links in this post on delicious: http://www.delicious.com/dougvdotcom/custom-errordocuments-available-for-download