htaccess

How to enable Mod_Rewrite in Apache2 on Ubuntu

Monday, January 9th, 2012 | Business | 11 Comments

LinuxWas just doing this, and thought it’d be a nice guide to write up.

I’m assuming you already have Apache2 installed on your machine.  If not, check how to install Apache 2 on Ubuntu.

Mod_rewrite is a module that allows runtime modification of the URL structure.  Typically this is to allow .htaccess directives to implement friendly URLs.  This is done frequently in WordPress and many other CMSes.

Link to the Module

Apache 2 on Ubuntu is a bit different than some servers, as Apache is usually controlled in the /etc/apache2 directory.

There will be 2 directories for enabling mods, they are /etc/apache2/mods-enabled and /etc/apache2/mods-available.  Mods-enabled includes a list (hopefully links) of files that are enabled via the configuration file (if you look, there’s a command to load all modules in that directory).  Mods-available, is all modules you can enable.

To create the link:

cd /etc/apache2/mods-enabled
ln -s ../mods-available/rewrite.load rewrite.load

› Continue reading

Tags: , , , , ,

Protect Client Search Engine Placement with 301 Redirects

Wednesday, October 15th, 2008 | Business | 2 Comments

This is a big win for us web developers.  It helps maintain all the SEO work that has gone into a site, and lets us move site architecture around with minimal impact.

Many times I run across companies whose website just went from ASP/CFM/JSP/PHP/CGI/HTML/HTM to ASP/CFM/JSP/PHP/CGI/HTML/HTM.  Fill in the blank, migrating from one platform to another is a big deal.  To make matters worse, how is a search engine supposed to know NOT to link to an old file, and to redirect the same relevancy to the new file?

The magic of 301 Redirects

301 is an HTTP Status code (just like 404 and others, 403, 500, etc).

301 tells browsers and search engines that a page has been “Moved Permanently”

 

How can you do a 301 redirect?

First off, do NOT attempt redirecting unless you know specifically what to do.  Trying to implement a meta-refresh tag will hurt you more than it will help.  Search engines have become wise to the meta-refresh game that spammers have been involved with.  Do not do it.

There are 2 routes to take, server side, and code side.

 

Server Side 301 Redirects

If you’re lucky enough to be working on a server supporting .htaccess files, your life is easy.  

  1. Create a file called “.htaccess” in the root of your website
  2. Open the file in a text editor
  3. Set the contents to the following (replacing original, and new):

Redirect 301 /original/original.html http://www.yoursite.com/new/new.html

OR if you want to wildcard it:

RedirectMatch 301 (.*)\.htm$ http://yoursite.com$1.html

If your server is IIS, you can do a redirect with the following:
  1. In IIS (internet services manager), right click on the old file
  2. Select “a redirection to a URL”
  3. Enter the URL for the new page
  4. Select “The exact URL entered above” and “A permanent redirection for this resource.”
  5. Click “Apply”
Code Implementation of 301 Redirects (PHP, ASP, JSP)
Of course a 301 redirect can be implemented in the front end code for a specific file.  That can be done fairly effectively with very basic code.
Following are some examples of redirects in some popular languages:
PHP header( "HTTP/1.1 301 Moved Permanently" );
header( "Status: 301 Moved Permanently" );
header( "Location: http://www.newsite.com/" );
exit(0);
 
ASP response.setStatus(301);
response.setHeader( "Location", "http://www.newsite.com/" );
response.setHeader( "Connection", "close" );
 
JSP response.setContentType("text/html");
response.setDateHeader("Expires", 0);
response.setHeader("Location", "http://www.newsite.com/new.php");
response.setStatus(301);
Of course if you want to get fancier, you could create a script that automatically detects the page name and derives the new page name from that string (example done in JSP):
HttpServletRequest req1=(HttpServletRequest) request;
StringBuffer ReqUrl= req1.getRequestURL();
String RequestUrl=ReqUrl.toString();String source;
String str; 

source = RequestUrl;

str = source.substring(0, source.indexOf(".jsp"));

response.setContentType("text/html");
response.setDateHeader("Expires", 0);
response.setHeader("Location", str+".php");
response.setStatus(301);

Conclusion
That’s it.  It should be easy to move pages around from one platform to another, to a new domain, or a new directory structure.
Your clients will thank you, and it will save you the work of redoing all of your SEO work down the road.

Tags: , , , , , , ,


Please share, it makes me happy:

Subscribe to Email Alerts

Follow Me

Follow seangw on twitter

Archives

Categories

prestashop theme

virtuemart template