Permanent 301 Redirect the easy way

Posted on May 12, 2009 by GoogleThem.
Categories: html tips, SEO.

First, .htaccess and mod_rewrite can be very tricky and if you break your website redirect you may even fix it and not know because your browser session has not been restarted.

Use [R] instead of [R=301] while you are testing . When you are 100% certain the rule does exactly as it’s expected to, then switch it to [R=301] for your live site.

How to redirect any and all website pages to another website removing the page reference. This way if you have an old website with old links everyone will be redirected to the front door. Search engines will see the permanent 301 redirect and update their index to not list your old website.

# redirect anything with base url in the second line to the first one and remove any page references
redirectMatch 301 ^(.*)$ http://mynewwebsite.com
redirectMatch permanent ^(.*)$ http://www.myoldwebsite.net

Redirect with URL masking:
from: http://answers.yahoo.com/question/index?qid=20090904141904AAd3mjB
“the apache rewriteengine doesn’t have any functionalities to mask URLs. Traditional masking techniques (pull out the source of the page that’s been masked and you’ll see) is done through a frame.


However you can accomplish dynamic masking by a little bit of additional code (I have an example in django but it’s out of the scope of this discussion.)

Here’s a basic masking frame

<frameset rows = “100%, *” border = “0″ framespacing=”0″ frameborder=”0″>

<frame noresize = “” src = “http://yourwebsite.com/”></frame>

</frameset>

@EDIT:

That would be for contemporary redirects.

Let’s say that you want host1.com to redirect to mysite.com

The usual .htaccess redirect rule would be

RewriteEngine on
RewriteCond %{HTTP_HOST} ^host1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.host1.com$
RewriteRule ^.*$ “http\:\/\/mysite\.com\/” [R=301,L]

in apache.

(The string of ‘\’ acts as escape sequences for [':','/','.'], with a R response code of 301)

However this does not allow you to mask the pages.

In order to achieve masking effects, use the following as your HTML in the index.html file on host1.com

<frameset rows = “100%, *” border = “0″ framespacing=”0″ frameborder=”0″>

<frame noresize = “” src = “http://mysite.com/”></frame>

</frameset>

Just copy paste this into the index.html file under host1.com and it should work.”

More .htaccess tricks with various redirects and how to do them:

from: http://corz.org/serv/tricks/htaccess2.php

My HTML tips and tricks

Posted on March 1, 2009 by GoogleThem.
Categories: html tips.

Extra spaces inside tables, usually at the bottom of the td (table cell) and hanging bottoms after forms.

This is assuming you don’t have problems with the cellpadding and cellspacing not being set explicitly to 0. You can have tables with cellpadding and cellspacing and still not have that annoying space below your content at the bottom of the table! Read on…

In the old days, the extra space at the bottom of a table was due to having the </td> on the next line after the content inside the table. To make the code readable, most people and web page creation programs will put the closing table data tag on it’s  own line. This creates the problem. The workaround is to close the table data on the same line and don’t leave extra content like a space before the </td> tag.

If you still have the problem: HTML rendering engines in the browsers add spaces before and after block level elements including forms. They almost always suppress the space before the form and only show the space after. If you are using style sheets (refer to my css tricks), you can easily defeat this by specifying a margin of 0.

If you still have the problem and are using pure HTML without css:
You can add just a bit of css to fix your entire page, not your entire website, that would require declaring an external stylesheet on every page. Put this inside your head tag:
<style>
h1, h2, h3, h4, h5{margin:0px}
</style>

Just substitute whatever block level element is giving you problems with the extra space below.

Image not showing or broken image icon:

1) “View Image” in your browser and look at the file path in the URL bar, that will tell you where the webpage code is saying the image is supposed to be. Put the image up at that path or edit the webpage code to reflect the actual location.

2) Make sure you don’t have a meta tag <base href=”http://www.mywebsite.com/” />  which is telling the webpage to locate image files that are relative linked to look in a certain location with a base path and then add the filename to that. If you do have the meta base href tag, you can change your webpage code to look in an “images/myimage.jpg” folder.

My .htaccess tricks

Posted on January 14, 2009 by GoogleThem.
Categories: html tips, Web Development Tricks.

To show a directory listing specifically in that directory only place this in the .htaccess file that resides in that folder:

IndexOptions -FancyIndexing
 Options +Indexes




To deny a directory listing, place this the the .htaccess in that directory or in a higher directory:

 Options -Indexes
 

Now a 403 error will be returned instead.



To redirect to a subdirectory or a folder:


RewriteEngine On
RewriteBase /
RewriteRule ^index.(.*)?$ http://domain.com/subfolder/ [r=301]

This will redirect any attempt to access a file named index.something to your subfolder, whether the file exists or not.

A simple HTML redirect is an alternative:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>
Stop SOPA