Variable Visions

Redirects compared - client vs server side

Published Wed. Oct. 31, 2012

Server side redirects and rewrites are the way to go but client-side redirects are ok if your redirecting a php header after a form is submitted or If you want the redirect to occur upon an event like a click to invoke a javascript redirect


<script type="text/javascript">?window.location = "";?</script>
<button onclick="window.location = ''">GO</button>
<script language=”javascript”>


<script language=”javascript”>



<script language=”JavaScript”>



Of course these only work when a browser has Javascript turned on.
There is an HTML way if your afraid js will be turned off. This client-side redirect is kinda old now though.

<meta http-equiv="refresh" content="0;url="/>


php (server side)

header(" Location:");

These seems common when redirecting a user after a form is submitted.


apache (server side)

Redirect 301 /old.php
RewriteRule ^articles/(.*) /index.php?article=$1

I use Redirect to send a user to a completely new and different url form the one they clicked on

I use Rewrite when I want to turn my ugly query string URLs into pretty SEO friendly URLs. This means that the same URL is then accessible form BOTH URLs. I just don't use the ugly urls in the site map or links. (hopefully to prevent duplicate content.

I also use a Rewrite condition and rule to redirect my url if typed without the www. I don't think I need the canonical tag here but what if someone links to my site without the three dubs? Will I get hit with a duplicate content slap?

Next time, I'll talk about how to set up these redirects in the httpd.conf file rather then the .htaccess file to speed things up.

from the Apache site...
Rewrite vs Redirect
Apache has two ways to serve one page when you were asked for another:
Rewrite* rules via mod_rewrite (e.g. RewriteRule, RewriteCond), and
Redirect* rules via mod_alias (e.g. Redirect and RedirectMatch).
What are the differences?
    •    mod_rewrite is generally considered the more powerful, and more complex, solution. It offers the RewriteCond directive, which lets you only run a Rewrite rule if certain conditions are met.
    •    mod_alias is simpler, and lets you match on a simple string or on a regular expression, but does not allow you to put conditions in (other than those defined by the regexp)

Keywords:mod_rewrite, mod_alias, client-side redirect, server-side redirect