• Tidak ada hasil yang ditemukan

301-redirect.ppt 331KB Jun 23 2011 07:22:58 AM

N/A
N/A
Protected

Academic year: 2017

Membagikan "301-redirect.ppt 331KB Jun 23 2011 07:22:58 AM"

Copied!
22
0
0

Teks penuh

(1)

© 2009 Stephan M Spencer Netconcepts www.netconcepts.com sspencer@netconcepts.com

301 Redirect:

How Do I Love You, Let Me Count the Ways

(2)

Time To Drink From the Firehose!

No need to take furious notes though.

(Phew!)

Download this Powerpoint right now

from

(3)

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

http://www.example.com/new_url.htm

– Redirect 301 /old_dir/ http://www.example.com/new_dir/

– Redirect 301 / http://www.example.com

Pattern matching can be done with RedirectMatch

301

(4)

301 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”

(5)

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

(6)

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].

(7)

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

(8)

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 \.

(9)

Let’s Go Deeper Down the Rabbit Hole

A more complex example

– RewriteCond %{HTTP_HOST} !^www\.example\.com$

[NC]

– RewriteRule ^(.*)$ http://www.example.com/$1 [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

(10)

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]+(&?.*)$

(11)

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

(12)

301 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

(13)

301 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

(14)

Canonicalization

Non-www and typo domains

– (The example mentioned earlier...)

– RewriteCond %{HTTP_HOST} !^www\.example\.com$

[NC]

– RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

HTTPS

– (If you have a separate secure server, you can skip this

first line)

– RewriteCond %{HTTPS} on

– RewriteRule ^catalog/(.*)

(15)

Canonicalization

If trailing slash is missing, add it

– RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

– WordPress handles this by default. Yay

(16)

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

(17)

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 (.*) http://www.example.com$1 [I,RP,L]

Non-www and typo domains

– RewriteCond Host: (?!www\.example\.com)

(18)

More IIS Examples

Drop the default

– RewriteRule (.*)/default.htm $1/ [I,RP,L]

Add trailing slash if it’s missing

– RewriteCond Host: (.*)

(19)

Conditional Redirects?

Risky territory! Read

Redirects: 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]

(20)

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

http://yoast.com/phpsessid-url-redirect/

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

(21)

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

(22)

Thanks!

This Powerpoint can be downloaded from

www.netconcepts.com/learn/301-redirect.ppt

For 180 minute long

screencast

(including

90 minutes of Q&A) on

SEO for large

dynamic websites

– including

transcripts

– email

seo@netconcepts.com

Questions after the show? Email me at

Referensi

Dokumen terkait

Bila pemenang cadangan pertama tidak bersedia juga menerima penunjukan sebagai penyedia barang/jasa pekerjaan tersebut diatas, maka akan diberikan kepada pemenang cadangan

[r]

Pada hari ini Sabtu tanggal Tiga belas Bulan Desember tahun Dua ribu empat belas, dimulai pukul 10.15 WIB bertempat di Panti Sosial Bina Netra Wyata Guna B andung, telah

Berdasarkan hasil Berita Acara Evaluasi Dokumen Penawaran (Tahap I) Nomor BA.13/Dredge/Ad.Smd/IV-2012 tanggal 27 April 2012, dan Berita Acara Evaluasi Dokumen Penawaran (Tahap

apabila yang bersangkutan mengundurkan diri dan masa penawarannya masih berlaku dengan alasan yang tidak dapat diterima secara obyektif oleh Panitia Pengadaan Barang/Jasa,

- Motivasi Mutasi, Promosi dan demosi adalah tiga hal yang berkaitan dalam memotivasi diri dari karyawan untuk meningkatkan prestasi kerja... 2.3

Sistem pendidikan jarak jauh adalah kaedah pengajaran dimana aktiviti pengajaran dilaksanakan secara terpisah dari aktiviti belajar. Sebagian besar karena tempat

Buku ensiklopedia animal yang mengenalkan dunia binatang pada anak tentu akan menambah pengetahuan mereka dari sisi.. keingintahuan pada dunia binatang seperti