redirect

Apache 301 redirects on GoDaddy web hosting

I have a shared web hosting account on GoDaddy, and wanted to do a 301 redirect with an Apache .htaccess file. For some unknown reason GoDaddy’s web interface wasn’t working for this, so I thought I’d fix the problem manually.

In short, this did NOT work:

Redirect 301 /the-old-uri  http://alvinalexander.com/the-new-uri

ScalaJ-HTTP examples: GET, POST, handling redirects

Table of Contents1 - Handling redirect requests with ScalaJ-HTTP2 - ScalaJ-HTTP GET request example3 - Setting ScalaJ-HTTP timeout values4 - A ScalaJ-HTTP POST request example5 - ScalaJ-HTTP: Summary

If you ever need some good ScalaJ-HTTP examples, see the test files in the project, including this HttpBinTest.scala file. That file currently shows a number of good ScalaJ-HTTP examples, including GET, POST, redirect examples with Scala.

See that page for a full list of examples, but for my own use, here are a few of them.

Nginx configuration: How to drop the query string on a rewrite

As a quick note, if you need to drop the query string when configuring an Nginx rewrite request, this syntax works:

rewrite ^/foo/bar.*$  /bar?  permanent;

The key is to use the ? character at the end of the URL/URI you are redirecting users to. That drops the query string, so the user will be redirected to the exact /bar URI.

For more information, see the Nginx rewrite module page.

What is the Unix/Linux “bit bucket”?

Unix/Linux FAQ: What is the “bit bucket”?

The bit bucket is a way of referring /dev/null. Sending output to the /dev/null device file is like sending output directly to the trash. That’s why you see code like this a lot of times:

aCommand 2> /dev/null

That’s a way of saying, “Run the command aCommand and send it’s error output to the bit bucket.” In use like this, “error output” refers to STDERR, and redirecting STDERR to the bit bucket is the same as throwing it into the trash (or throwing it into a black hole, if you prefer).

Another way you can demonstrate this is by sending STDOUT to the bit bucket. In this next example, I send the output from the ls command to the bit bucket:

ls -l > /dev/null

If you run that command, you won’t see any output because the standard output — STDOUT — is redirected to /dev/null. There’s no practical reason for doing this in the real world; I just wanted to demonstrate that you can redirect both STDOUT and STDERR to the bit bucket, if you ever need to.

For more information, here’s a short tutorial on How to redirect Unix STDOUT and STDERR to the same location.

Handling trailing slash characters with Nginx 301 redirects

As a quick Nginx configuration example, if you need to configure a 301 Redirect with Nginx, and you also need to account for trailing slash characters in the original URL, I can confirm that this solution works for me:

rewrite /foo/bar/baz/?$  /foo/bar/baz.html permanent;

This Nginx configuration line will forward both of these URIs to the new URI:

How to redirect the STDOUT and STDIN of external commands

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.15, “How to redirect the STDOUT and STDIN of external commands.”

Problem

You want to redirect the standard output (STDOUT) and standard input (STDIN) when running external commands. For instance, you may want to redirect STDOUT to log the output of an external command to a file.

Solution

Use #> to redirect STDOUT, and #< to redirect STDIN.

A list of Play Framework controller action results (result types)

When you’re writing Play Framework controller actions, you’re typically going to be returning a Play Results, with the most common result being Ok. However, your controller actions can return many different result types. This table shows some of the most common result types that you can use instead of Ok:

Nginx 301 redirect examples

Here's an example of how to do a 301 Redirect with Nginx:

rewrite /blog/Content/2/8/581 /blog/post/java/dos-batch-files-compile-run-java-program-create-jar-file permanent;

As you can see, Nginx uses the keyword permanent instead of 301.

I just did a few hundred of these on this devdaily.com website. I put them in a separate "redirects.conf" file, and included that file into my main nginx.conf file like this:

Drupal - How to redirect a user when altering an existing form

Drupal form FAQ: How do I redirect a user when they submit a form, and I'm writing a hook_form_alter function to alter that form?

In Drupal 6 you set the "$form['#redirect']" property in your hook_form_alter function when you alter the form, like this:

$form['#redirect'] = 'thank-you';

That syntax tells Drupal to redirect the user to the "/thank-you" URI on your website.