Subscribe to our Monthly Newsletter

Doing Page Redirects the Right Way

redirectDoing Page Redirects the Right Way

Redirecting webpage requests is useful when you’ve deleted outdated pages, or when moving your site to a new domain. Rather than give site errors to visitors, and tempt them to leave your site, you should make sure they are redirected to a page on your website.

There are several ways of doing this. We recommend server-side 301 redirects in most cases but there’s also a method that uses HTML that could be used in a pinch, and especially when you don’t have full server access.

HTML Meta Redirect

The HTML meta element can be used to redirect the user to another page after a specified number of seconds.

Place the following in the <header> tags:

<meta http-equiv=”refresh” content=”5;URL=’http://www.example.com/newPage‘” />

Within the “content” field, the first number specifies the number of seconds it takes to redirect, with “0” being an immediate redirect. Having a delay could be helpful if you want to let visitors know that a certain page or site has been removed, and that they’re being redirected to another location.

But there are many reasons to avoid HTML meta redirects. They are not particularly good for maintaining search engine ranking. They also often break the “back” button, so when the user tries to go back, it triggers the refresh, sending them back to the original page. Also, it might not work with all user agents such as screen reader software according to W3C.

Server-Side 301 Redirect Scripts

Server-side scripts or configuration file can send an appropriate redirect status code (for instance, “301” means that a page has permanently moved to a new location) and a location header specifies another URL for redirection. When the browser receives this response, the location bar changes and the browser makes a request with the new URL.

There are several ways of doing 301 redirects.

PHP Header Method

In PHP, developers can send a raw HTTP header with the header method. The code below sends a 301 status code and a new location. If no status is explicitly set, it sends a 302 status code, which basically specifies that it’s a temporary redirect and the new path is not cached in a visitor’s browser.

Example Code:

<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://www.example.com/newPage.php“);
?>

It’s important to note that the header() function must be called before any actual output is sent for the redirect to work.

You can also use PHP’s power as a programming language to automatically redirect pages such as pages not found on your website. For that particular situation, SitePoint provides a tutorial on creating a PHP script that sends the site visitor to the correct page or similar content.

The Apache Redirect Method

If you have access to make changes to the .htaccess file on your Apache server, you can do simple Apache redirects. You need to locate the .htaccess file and open it in a text or code editor.

You’ll be making the redirects using the following basic syntax:

Redirect [status] URL-path URL

Example Code:

redirect 301 /oldPage.html http://www.example.com/newPage.html

After “301”, specify the file or the folder to be redirected, and then the destination.

For more elaborate Apache redirection, you might want to look into how to do URL rewrites. Apache also provides a guide to common rewrite scenarios.

Other Languages

W3 describes how to do server redirects in Java Servlets or JavaServer Pages (JSP), and in Active Server Page (ASP) with VBScript in its online documentation. And 301 redirects can be done in other languages such as Ruby on Rails.

A Note on Staying Search Engine-Friendly

In terms of keeping pages optimized for search engines, Google says that 301 redirects are the best way to ensure that users and search engines are directed to the correct page. They capture the intended traffic from that link for the page it redirects to.

According to Google’s Matt Cutts, there is no limit to how many 301 (or permanent) redirects you can do between one page and another. But redirecting multiple times (ie. hopping from page 1 to page 2 to page 3, etc.) can cause the Google crawler to give up after a few hops and also increase the overall page load time. Cutts recommends limiting redirects to a maximum of around 4 or 5 hops.

To redirect people who access your site through several different URLs, for instance, . http://example.com/home, and http://home.example.com to a preferred (or “canonical”) destination, then you would also set your preferred domain in Google Webmaster Tools.

Conclusion

Page redirects can send visitors to the most current resources, but also help when, for instance, someone sent out an incorrect link URL. For these reasons alone, page redirects can be very common. And when it’s necessary to redirect pages, it’s best to use server-side 301 redirects because they’re less likely to confuse users as well as search engine crawlers.

Continue Reading · Comments { 0 }

What Exactly Is “void 0” – And What’s It For?

nullHey there, folks! Today, we’re going to talk all about one very specific command in JavaScript: “void (0)”, also seen as “void 0”. It’s a quirky command; one whose purpose many aren’t entirely clear on. To confuse things even more, there’s also an error message: “javascript:void(0)” that is basically unrelated. We’ll talk about both to clear up the confusion.

Let’s see if we can clear things up a bit.

Shall we begin?

The “javascript:void(0)” Error Message

Right. According to Tech-Faq, this is a fairly unique error, primarily because it can be encountered by users of pretty much any operating system.

There are quite a few issues which might cause this troublesome little error prompt to pop up:

  • Conflicts with ad blockers/popup blockers
  • Poorly-written JavaScript
  • Disabled JavaScript
  • An Outdated Web Browser
  • Use of a proxy server

As I’m certain you’ve noticed, the error is caused by the user in all but the second case, where it’s usually caused by “web page authors who don’t check their script for compatibility.” In that circumstance, the user has no choice but to use the browser that the script was written for.

If you’re a developer or sysadmin, this is a reminder to test your scripts in as many browsers as possible.

And now for something completely different…with a very similar name.

The “void” Operator and “void 0”

“void” is an operator that can be applied to any argument in a script. The syntax goes a little something like this:

<head>
<script type=”text/javascript”>
<!–
void func()
javascript:void func()

or

void(func())
javascript:void(func())
//–>
</script>
</head>

When “void(0)” is applied to an expression or argument, the value returned is always “undefined”, regardless of the other values present. That may seem somewhat useless at first glance; and more than a little obtuse. After all, why not simply use “undefined” itself?

For that matter, why do you need any of this stuff at all?

A couple reasons. Let’s start by explaining why the “undefined” value is important in the first place. Believe it or not, there’s actually a ton of different reasons one might use it.

Why Use “void”?

According to Tizag, one of the most common uses for “void” is so that JavaScript can be executed in a web browser without having to load a new page. See, most browsers allow you to run scripts by entering it into the URL bar. With “void (0)”, you can do this without having to switch pages – it effectively cancels out the page load.

This allows you to build a link whose sole purpose is the execution of JavaScript code (though some might argue that isn’t really the purpose of a link).

“Web browsers will try to take whatever is used as a URL and load it,” reads Tizag’s tutorial. “The only reason we can use a JavaScript Alert statement without loading a new page is because alert is a function that returns a null value. That means that when the browser attempts to load a new page it sees null and has nothing to load.”

“The important thing to notice here,” the tutorial continues, “is that if you ever do use a JavaScript statement as the URL that returns a value, the browser will attempt to load a page. To prevent this unwanted action, you need to use the void function on such statement, which will always return null and never load a new page.”

What’s The Difference Between “void (0)” and “undefined”?

The problem with simply using “undefined” instead of “void (0)” is that the former isn’t a reserved word – it’s generally a variable, rather than an operator; in some JavaScript environments, it’s actually a global. It may occasionally have the value of “undefined”, but that’s not guaranteed, because somebody can always assign it a value that isn’t “undefined.”

On the other hand, “void” always returns the value of “undefined”. As far as the difference between “void (0)” and…well “void” with any other characters; that’s kind of irrelevant. “void “dingleberries”” would work just as well as “void (0)” or “void 0”.

Image credit: Andreas

Continue Reading · Comments { 0 }

A Complete Guide To chmod: recursive, force, and More

What Is chmod?

The purpose of chmod – which stands for Change Mode – is to change access permissions for files and directories. It’s also able to modify special mode flags, such as sticky bit mode, SUID, and SGID. It’s been present in Linux and other Unix-like operating systems since the 70s, in AT&T’s Unix Version One, but in the time it’s been in use, a number of access_control_lists have been added to increase the flexibility of the command.

How Is chmod Used?

(Advice in this section is courtesy of Computer Hope).

The proper syntax for chmod, depending on how you want to use it, is as follows:

chmod [OPTION]… MODE[,MODE]… FILE…
chmod [OPTION]… OCTAL-MODE FILE…
chmod [OPTION]… –reference=RFILE FILE..

Options

In all cases, you start by defining which options you want to implement. The most common options include verbose (-v or –verbose; shows the items you’re processing), recursive (-R or –recursive; includes objects stored in subdirectories) and force (which ignores errors and continues applying chmod). In the event that a symbolic link is included, chmod includes the file or files specified in the link.

Additional chmod options include…

  • -c or –changes: Describes the action for each file whose permissions change.  
  • -f, –silent, or –quiet: Instructs chmod not to print out error messages.
  • –preserve-root: An option that can only be applied with –recursive; this prevents any attempts to recursively change the root directory.
  • –no-preserve-root: Ignores any preceding –preserve-root options. Again, only relevant when using –recursive.
  • -reference=ref_file: Changes the mode of each file so that it’s the the same as the reference file specified.

Modes

(The majority of the information in this section is provided courtesy of freebsd)

Absolute Modes

There are eight different file permission modes in Linux: read, write, and execute; read and write, read and execute, read only, write and execute, write only, execute, and none. With chmod, these modes are defined in an octal format, using 0 through 7. There are four digits in the command; the first digit is optional and used to define special flags while the second to fourth are used to set permissions for the file’s owner, the user group, and other users outside that group.

These octal values represent absolute modes, which are put together from the sum of one or more of the following:

4000: (setuid): Sets executable files to run with the effective uid of the file owner. Directories with this bit will force all files/subdirectories created in them to be owned by the directory owner.

2000: (setgid): This will run executable files with the effective group id of the file owner.

1000: (sticky bit): Used to indicate special treatment for directories. Read more about it here.

0400: Allows read exclusively by the file owner.

0200: Allows write exclusively by the file owner.

0100: Allows execution exclusively by the file owner.

0040: Allows read exclusively by group members.

0020: Allows write exclusively by group members

0010: Allows execution exclusively by group members

0004: Allows other users to read

0002: Allows other users to write

0001: Allows other users to execute

Symbolic Modes

Modes can also be defined symbolically, with the following syntax:

mode ::= clause [, clause …]
clause ::= [who …] [action …] action
action ::= op [perm …]

who     ::= a | u | g | o
op ::= + | – | =
perm    ::= r | s | t | w | x | X | u | g | o

Who specifies the user, group, and other parts of Mode. Perm represents portions of mode as follows:

  • r: Read
  • s: Setuid and Setgid
  • t: Sticky
  • w: Write
  • x: Execute/search
  • X: Execute/search if the file is a directory or execute/search is set in the original mode Only used in conjunction with the op symbol +
  • u: User permission bits in the original file
  • g: Group permission bits in the original file
  • o: Other permission bits in the original file.

Further, op represents the operation performed, taking into account the following:

  • “+” Only works if ‘perm’ has been specified. If no value has been specified for who, each bit specified in perm is set. If both who and perm are specified, the mode bit represented by them is set.
  • “-“ Has the opposite effect of ‘+;’ clearing values instead of setting them.
  • “=” Clears the who value. If no who value is specified; clears owner, group, and mode. Following that, if who still is unspecified, sets perm values.

Finally, clause represents operations to be performed on the mode bits, in the order specified.

What chmod Operations Should You Generally Avoid?

There’s really only one chmod operation that you should generally avoid, as using it can cause some pretty significant security issues on your server. This is chmod 777.  There’s a very good reason you shouldn’t use this one – it gives full permissions to anyone who accesses your server.

That represents a pretty significant security risk. Instead, it may be better to simply use chmod 775, or have whatever script you’re creating run as the owner of the files with the SUID flag.

In addition, where directories are concerned; avoid using 664 for your permissions. You need to execute permissions on a directory in order to access it; removing that permission will break whatever you apply it to.

A Few Additional chmod Tips

We’ll wrap up with a bit of extra advice related to chmod:

    • Remember that you need read permissions in order to list directories and subdirectories.
    • You can set all files in a folder or directory to writeable with chmod -R 775 [directory]
    • Files and directories can have permissions applied independently through the find command. For example:
  • find . -type f -exec chmod 640 {} \; for files and find . -type d -exec chmod 750 {} \;
  • Generally, “site chmod” through ftp has only basic functionality – it’s not the full Linux command, so what you can do with it is extremely limited.
Continue Reading · Comments { 0 }

Why You Can’t Afford Not To Protect Yourself From DDoS Attacks

ddos

Image Credit: Thierry Ehrmann

On February 11, 2014; Cloudflare’s European and U.S. data centers very nearly had their networks taken offline by the largest Distributed Denial of Service attack in history. Directed at one of Cloudflare’s customers, malicious traffic at the time of the attack topped 400 Gbps, taking place over a new – and previously undefended – attack vector. Worse still, many have pointed to this attack as a sign of worse things to come.

“Someone’s got a big, new cannon,” said Cloudflare CEO Matthew Prince over Twitter, talking about the attack. “Start of ugly things to come.”

He’s not wrong. DDoS attacks are on the rise, and it’s going to get worse before it gets better. As groups like Derptrolling and Lizard Squad parade about liberally shelling websites and networks, other, more insidious criminal groups operate behind the scenes, using DDoSing as a cover for theft or fraud. Continue Reading →

Continue Reading · Comments { 0 }

Why Your Startup Can Fail After Year Five – And How To Prevent That From Happening

new york skylineThere’s a mantra that’s all too commonly repeated in the small business sector – the notion that upwards of 80% of businesses fail, usually within the first year. It’s an intimidating figure; one that drives home the difficulty of success as an entrepreneur.

It’s also woefully inaccurate.

“As far as we can tell,” writes Glenn Kessler of The Washington Post, “there is no statistical basis for the assertion that 9 out of 10 businesses fail.

It appears to be one of those nonsense facts that people repeat without thinking too clearly about it.”

The problem is that everyone seems to have a different idea of what constitutes failure.

If a business doesn’t return on the initial investment made by venture capitalists, but otherwise manages to stay afloat, has it failed? If a company ends up being acquired or absorbed by another organization, is that failure? If a startup doesn’t meet one of its projected goals, is it dead in the water?

“About three-quarters of venture-backed firms in the US don’t return investor’s capital, according to recent research by Shikhar Ghosh, a senior lecturer at Harvard Business School,” writes Deborah Gage of The Wall Street Journal. “His findings are based on data from more than 2,000 companies that received venture funding from 2004 through 2010.”

“There are also different definitions of failure,” Gage acknowledges. “If failure means liquidating all assets, with investors losing all their money, an estimated 30% to 40% of high potential U.S. startups fail, he says. If failure is defined as failing to see the projected return on investment—say, a specific revenue growth rate or date to break even on cash flow—then more than 95% of start-ups fail, based on Mr. Ghosh’s research.”

Not only that, notes Kessler, different industries have different failure rates. A startup in the home computing sector, for example is going to be dealing with different challenges than one involved with manufacturing; one is going to be either more or less likely to fail than the other. Lumping all industries together under one umbrella only skews the data further. Continue Reading →

Continue Reading · Comments { 0 }

The Anatomy Of EMC: DAE, DPE, SPE, And More

emc vnxParticularly if you’re new to the hosting space, all the jargon floating around about server architecture can be more than a little overwhelming.

At times, it can almost feel like people are speaking an entirely different language.

Today, we’re going to see if we can eliminate at least a bit of the confusion and mysticism.

We’re going to go over some of the terminology, components, and concepts commonly associated with EMC’s storage products – the VNX/VNXe series in particular.

Let’s get started.

(Definitions drawn from Justin Paul and StorageNerve) Continue Reading →

Continue Reading · Comments { 0 }

What Protocols Send & Receive Email With The Mail Server?

emailAlthough it may not seem like it today – in the era of Smartphones, Tablets, and Facebook – email’s a pretty revolutionary technology.

The development of the technology rendered a whole crop of traditional communications methods all but obsolete, and even though it’s been around for a while, it’s still every bit as relevant as it used to be.

When you think about it, that’s pretty impressive.

As such, it’s sort of a shame that there are so few people who understand how email works – and I mean really understand it; the protocols behind it and the infrastructure that makes it possible.

Let’s see if we can’t increase that number a bit. Today, we’re going to go over the four primary email protocols, explaining each one with regards to both its own purpose and the function of its peers.

Let’s get started. Continue Reading →

Continue Reading · Comments { 0 }

Using noatime, And Related Gems In Linux’s fstab

filespeedOne of the more important configuration files in Linux is the File Systems Tab: fstab.

Generally located in the /etc/ directory, it’s used to define how stuff should be mounted into Linux.

What that means is that if you have a decent idea what you’re doing, you can enjoy some pretty significant performance increases on any servers you happen to be running, whether they’re physical or virtual.

It sort of goes without saying that if you’re going to be running a server, you need to understand how it works.

That’s what we’re going to discuss today. We’ll start by explaining a bit about exactly how fstab works, before moving into a description of the different attributes you can define in order to modify how it loads your files. By the time we’re done, you should have a relatively sound concept of how to modify your Linux file system for performance – and for a whole lot of other stuff, too. Continue Reading →

Continue Reading · Comments { 0 }

Server Mania’s Complete Guide To Global Variables In PHP

dollar signHey there, folks! Today, we’re going to talk about the rather contentious subject of global variables in PHP. If you’re working with PHP, you’re probably going to run into them at one point or another – better you understand them right out the door, rather than having to learn them on the fly, right?

Shall we begin?

A Word Of Warning

Before we get started, it’s worth mentioning that global variables are something that should be used very sparingly. Not only can they be defined anywhere in the code – meaning there’s no one place to look to see what a variable’s used for – they also introduce additional parameters to your code, some of which may be impossible to document. On top of that, because of the way variables are created in PHP, there’s no way to be certain whether or not a particular variable has been created – and hence whether or not it is accessible.

Last, but certainly not least, other developers may use variables with names identical to yours – meaning that combining your code with other plugins or applications could break something fundamental.

So, I repeat, use global variables sparingly. It is also a good idea to name your variables with a prefix such as “$g_” so that you can immediately recognize them as globals when you refer to them. It’s also wise to include plenty of comments in your code regarding how the global should be used and where it is defined and modified.

However, it’s worth noting that globals in PHP are a bit different from globals in other languages, the scope being limited to a single HTTP request (which is actually smaller than session variables). Globals work a bit different in PHP and aren’t considered quite the mortal sin they would be considered in, say, C++. Globals in PHP are more like ThreadLocals in Java than true globals.

The most important thing to keep in mind is that you want dependencies to be plainly apparent and clearly spelled out (ideally in a central Registry). You should never use globals to magically teleport information. Continue Reading →

Continue Reading · Comments { 0 }

How The Software Defined Data Center Will Rock The Small Business World

clouds“Imagine,” reads a product page from IBM Systems, “an entire IT infrastructure controlled not by hands and hardware, but by software. One in which workloads like big data and analytics are serviced automatically by the most appropriate resource.”

This, explains IBM, is known as a software-defined environment – literally an environment in which hardware is functionally irrelevant; one in which everything is controlled through software switches. Continue Reading →

Continue Reading · Comments { 0 }