© 2009 Stephan M Spencer Netconcepts 301 Redirect: How Do I Love You, Let Me Count the Ways presented by Stephan.

Slides:



Advertisements
Similar presentations
Getting Your Web Site Found. Meta Tags Description Tag This allows you to influence the description of your page with the web crawlers.
Advertisements

Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
PHP Meetup - SEO 2/12/2009. Where to Focus? Ensuring the findability of content Ensuring content is well understood by search engines Maximizing the importance.
Part 2.  Arrays  Functions  Passing Variables in a URL  Passing variables with forms  Sessions.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
© 2008 Stephan M Spencer Netconcepts SEO Mistakes Most Bloggers Make By Stephan Spencer, Founder & President,
Marketer to Developer Translation SMX West February 9, 2009.
© 2008 Stephan M Spencer Netconcepts Unraveling URLs and Demystifying Domains presented by Stephan Spencer,
Wordpress SEO Basics Wordcamp Las Vegas Wordpress 2.7.
SEO Techniques Tech Talk 29 th August 2013 (By PEN Vannak)
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
1 Spidering the Web in Python CSC 161: The Art of Programming Prof. Henry Kautz 11/23/2009.
© 2008 Stephan M Spencer Netconcepts Bot Herding presented by Stephan Spencer, Founder & President, Netconcepts.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
ACM Web Development Workshop - PHP By Luis Torres.
Cookies Set a cookie – setcookie() Extract data from a cookie - $_COOKIE Augment user authentication script with a cookie.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
Server-side Scripting Powering the webs favourite services.
SIMPLE ROUTER The slide made by Salim Malakouti. Next we will create the Router  What do I we mean by a router?  Routers work similar to a map. It receives.
CSN09101 Networked Services Week 8: Essential Apache Module Leader: Dr Gordon Russell Lecturers: G. Russell, J. Jackson.
© 2005 Stephan M Spencer Netconcepts RSS, Blogs and Search Marketing: Leveraging the Power of RSS.
ASHIMA KALRA IMPORTANT TERMS.  WWW WWW  URL URL  HTTP PROTOCOL HTTP PROTOCOL  PROXIES PROXIES.
© 2009 Stephan M Spencer Netconcepts Tools, Glorious Tools presented by Stephan Spencer, Founder & President,
JavaScript, Fourth Edition
© 2006 Stephan M Spencer Netconcepts Site Architecture and Internal Linking By Stephan Spencer, Founder &
© 2006 Stephan M Spencer Netconcepts Search Engine Marketing by Stephan Spencer President, Netconcepts.
Python CGI programming
USING PERL FOR CGI PROGRAMMING
Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems.
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG 11 Kigali, Rwanda May 2010 Dorcas Muthoni Courtesy: Hervey Allen.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Quiz 15 minutes Open note, open book, open computer Finding the answer – working to get it – is what helps you learn I don’t care how you find the answer,
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Dynamic Sites for Fun and Profit Jake Baillie SES Chicago 2006.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
SEO Friendly Website Building a visually stunning website is not enough to ensure any success for your online presence.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Ten Tips for Search Engine Marketing Stephan Spencer President, Netconcepts
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Web Technologies Lecture 11 Implementing RESTful services.
© 2007 Stephan M Spencer Netconcepts SEO Best Practices for Bloggers.
© 2009 Stephan M Spencer Netconcepts Duplicate Content & The Canonical Tag By Stephan Spencer, President &
CSN09101 Networked Services Week 8: Essential Apache Module Leader: Dr Gordon Russell Lecturers: G. Russell.
© 2007 Stephan M Spencer Netconcepts Making Blogging and RSS Pay Off Driving Traffic and Sales Through Optimized.
Don’t look at Me!. There are situation when you don’t want search engines digging through some files or indexing some pages. You create a file in the.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
CITA 310 Section 4 Apache Configuration (Selected Topics from Textbook Chapter 6)
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Created By EZ Marketing Tech 1 +1 (347) | |
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Technical SEO tips for Web Developers Richa Bhatia Singsys Pte. Ltd.
Building Your Own Website Using:. Install & configure LAMP. Download WordPress and run it as a local website on your Raspberry Pi. Configure WordPress.
© 2005 Stephan M Spencer Netconcepts Search Engine Optimisation: Black Art or Sweet Science?
Managing State Chapter 13.
Redirection Allow requests to be moved about your file system or around the web ScriptAlias Allows you to run CGI scripts Simple to use.
Node.js Express Web Applications
Unix System Administration
PHP Training at GoLogica in Bangalore
The Request & Response object
SEO Mistakes Most Bloggers Make
Web Systems Development (CSC-215)
301 Redirect: How Do I Love You, Let Me Count the Ways
SEO Hand Book.
Presentation transcript:

© 2009 Stephan M Spencer Netconcepts Redirect: How Do I Love You, Let Me Count the Ways presented by Stephan Spencer, Founder & President, Netconcepts

© 2009 Stephan M Spencer Netconcepts Time To Drink From the Firehose!  No need to take furious notes though. (Phew!)  Download this Powerpoint right now from

© 2009 Stephan M Spencer Netconcepts Let’s Go Under the Hood with 301s  In.htaccess (or httpd.conf), you can redirect individual URLs, the contents of directories, entire domains… : –Redirect 301 /old_url.htm –Redirect 301 /old_dir/ –Redirect 301 /  Pattern matching can be done with RedirectMatch 301 –RedirectMatch 301 ^/(.+)/index\.html$

© 2009 Stephan M Spencer Netconcepts Redirects via Rewrite Rules  My preference is to use Apache’s mod_rewrite module and set up rewrite rules that use the [R=301] flag. Or if on Microsoft IIS Server, using ISAPI_Rewrite plugin.  The rewrite rules go in either.htaccess or your Apache config file (e.g. httpd.conf, sites_conf/…) –Precede all the rewrite rules with the line “RewriteEngine on” –If within.htaccess, also add another line “RewriteBase /”. Never add to the server config). Use it and you won’t have to have “^/” at the beginning of all your rules, just “^”

© 2009 Stephan M Spencer Netconcepts An Example Rewrite Rule  A simple example for httpd.conf –RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]  Store stuff in memory with () then access via variable $1  A rough equivalent for.htaccess –RewriteBase / –RewriteRule ^(.*)/?index\.html$ /$1/ [R=301,L]  Ah, but there’s an error with the rule immediately above. Hint: “.*” is “greedy”

© 2009 Stephan M Spencer Netconcepts The Magic of Regular Expressions  You need to become a master of pattern matching –* means 0 or more of the immediately preceding character –+ means 1 or more of the immediately preceding character –? means 0 or 1 occurrence of the immediately preceding char –^ means the beginning of the string, $ means the end of it –. means any character (i.e. wildcard) –\ “escapes” the character that follows, e.g. \. means dot –[ ] is for character ranges, e.g. [A-Za-z]. –^ inside [] brackets means “not”, e.g. [^/]

© 2009 Stephan M Spencer Netconcepts Regular Expression Errors  Incredibly easy to make errors in regular expressions  When debugging, RewriteLog and RewriteLogLevel (4+) is your friend!  Back to the previous example... –RewriteRule ^(.*)/?index\.html$ /$1/ [L,R=301]  What’s the problem?.* is greedy and so it will capture the “/” within memory – redirects to

© 2009 Stephan M Spencer Netconcepts Regular Expression Gotchas  “Greedy” expressions. Use [^ or.*? instead of.* –e.g [^/]+/[^/] instead of.*/.* –e.g ^(.*?)/ instead of ^(.*)/ .* can match on nothing. Use.+ instead –e.g..+/ instead of.*/  Unintentional substring matches because ^ or $ wasn’t specified or. was used for a dot instead of \. –e.g. ^/default\.htm$ instead of /default.htm

© 2009 Stephan M Spencer Netconcepts Let’s Go Deeper Down the Rabbit Hole  A more complex example –RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] –RewriteRule ^(.*)$ [L,R=301]  [NC] flag makes the rewrite condition case-insensitive  [L] flag saves on server processing  [QSA] flag not needed. It’s implied when using R=301. Don’t want the query string maintained, put ? at the end of the destination URL in the rule.

© 2009 Stephan M Spencer Netconcepts Speaking of Tracking Parameters  Here’s how to 301 static URLs with a tracking param appended to its canonical equivalent (minus the param) –RewriteCond %{QUERY_STRING} ^source=[a-z0-9]*$ –RewriteRule ^(.*)$ /$1? [L,R=301]  And for dynamic URLs... –RewriteCond %{QUERY_STRING} ^(.+)&source=[a-z0-9]+(&?.*)$ –RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]

© 2009 Stephan M Spencer Netconcepts More Fun with Tracking Parameters  Need to do some fancy stuff with cookies before 301ing? Invoke a script that cookies the user then 301s them to the canonical URL. –RewriteCond %{QUERY_STRING} ^source=([a-z0-9]*)$ –RewriteRule ^(.*)$ /cookiefirst.php?source=%1&dest=$1 [L]  Note the lack of a R=301 flag above. That’s on purpose. No need to expose this script to the user. Use a rewrite and let the script send the 301 after it’s done its work.

© 2009 Stephan M Spencer Netconcepts Retired Legacy URLs  Got legacy dynamic URLs you’re trying to phase out after switching to static URLs? 301 them... –RewriteCond %{QUERY_STRING} id=([0-9]+) –RewriteRule ^get_product.php$ /products/%1.html? [L,R=301]  Switching to keyword URLs and the script can’t do anything with the keywords if passed as params? Use RewriteMap and have a lookup table as a text file. –RewriteMap prodmap txt:/home/someusername/prodmap.txt –RewriteRule ^/product/([0-9]+)$ ${prodmap:$1} [L,R=301]

© 2009 Stephan M Spencer Netconcepts Retired Legacy URLs  What would the lookup table for the above rule look like? –1001 /products/canon-g10-digital-camera –1002 /products/128-gig-ipod-classic  DBM files are supported too. Faster than text file.  You could use a script that takes the requested input and delivers back its corresponding output. –RewriteMap prodmap prg:/home/someusername/mapscript.pl –RewriteRule ^/product/([0-9]+)$ ${prodmap:$1} [L,R=301]

© 2009 Stephan M Spencer Netconcepts Canonicalization  Non-www and typo domains –(The example mentioned earlier...) –RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] –RewriteRule ^(.*)$ [L,R=301]  HTTPS –(If you have a separate secure server, you can skip this first line) –RewriteCond %{HTTPS} on –RewriteRule ^catalog/(.*) [L,R=301]

© 2009 Stephan M Spencer Netconcepts Canonicalization  If trailing slash is missing, add it –RewriteRule ^(.*[^/])$ /$1/ [L,R=301] –WordPress handles this by default. Yay WordPress!

© 2009 Stephan M Spencer Netconcepts Iterative URL Optimization  When iteratively optimizing a page’s URL, 301 all previous iterations directly to the latest iteration. Don’t daisy chain 301s. –WordPress handles this beautifully, and by default –Tip: Use Netconcepts’ “SEO Title Tag” plugin to mass edit all your permalink post URLs and let WordPress handle the 301s automagically. But don’t then “set it and forget it”. Continue optimizing the URLs iteratively over time to maximize search traffic.SEO Title Tag

© 2009 Stephan M Spencer Netconcepts If You’re on Microsoft IIS Server  ISAPI_Rewrite not that different from mod_rewrite  Rewrite rules go in httpd.ini file  Precede first rewrite rule with “[ISAPI_Rewrite]”  Capitalization and IIS’ case insensitivity w.r.t. URLs –RewriteRule (.*) [I,RP,L]  Non-www and typo domains –RewriteCond Host: (?!www\.example\.com) –RewriteRule (.*) [I,RP,L]

© 2009 Stephan M Spencer Netconcepts More IIS Examples  Drop the default –RewriteRule (.*)/default.htm $1/ [I,RP,L]  Add trailing slash if it’s missing –RewriteCond Host: (.*) –RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,RP,L]

© 2009 Stephan M Spencer Netconcepts Conditional Redirects?  Risky territory! Read Redirects: Good, Bad & ConditionalRedirects: Good, Bad & Conditional  To selectively redirect bots that request URLs with session IDs to the URL sans session ID: –RewriteCond %{QUERY_STRING} PHPSESSID RewriteCond %{HTTP_USER_AGENT} Googlebot.* [OR] RewriteCond %{HTTP_USER_AGENT} ^msnbot.* [OR] RewriteCond %{HTTP_USER_AGENT} Slurp [OR] RewriteCond %{HTTP_USER_AGENT} Ask\ Jeeves RewriteRule ^(.*)$ /$1 [R=301,L]  browscap.ini provides spiders’ user agents

© 2009 Stephan M Spencer Netconcepts Conditional Redirects Not Necessary  Almost always another way (w/o using user agent or IP)  In the above example, simply 301 everybody – bots and humans alike – and stop appending PHPSESSID –See for more on this. –If you have to keep session IDs for functionality reasons, you could use a script to detect for whether the session has expired, and 301 the URL to the canonical equivalent if it has.  Matt Cutts will be talking about this topic tomorrow in “Ask the Search Engines” session. Don’t miss it!

© 2009 Stephan M Spencer Netconcepts Capture PageRank on Dead Pages  Traditional approach is to serve up a 404, which drops that obsolete URL out of the index, squandering that URL’s link juice.  But what if you 301 redirect to something valuable (e.g. your home page or the category page one level up) and dynamically include a small error notice?  Or return a 200 status code instead, so that the spiders follow the links on the error page? Then include a meta robots noindex so the error page itself doesn’t get indexed.  IMPORTANT: Don’t respond to garbage (nonsense) URLs with anything but a 404 status code. Googlebot looks for this!

© 2009 Stephan M Spencer Netconcepts Thanks!  This Powerpoint can be downloaded from  For 180 minute long screencast (including 90 minutes of Q&A) on SEO for large dynamic websites – including transcripts –  Questions after the show? me at