Forum Moderators: phranque
301'ing over 50 thousand pages
Change all the Redirect instructions to use RewriteRule syntax with the [R=301,L] flags. The target must also include the protocol and domain name.
The internal rewrites must be moved to the very end of the file. Currently the first internal rewrite grabs all the requests, and the longer rule at the end never gets to run. The "catch all" rule must be the very last rule of all.
# REMOVE PHP EXTENSIONS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA] 1. Is it right that + and - in the old URL become _ in the new URL?
2. Is the 7ua11 in the old URL, still 7ua11 in the new URL, or is it 7ub21? If the latter, then RewriteRule has NO WAY to know how to change the numbers.
# ERROR DOCUMENTS
ErrorDocument 400 http://website.com/error
ErrorDocument 401 http://website.com/error
ErrorDocument 403 http://website.com/error
ErrorDocument 404 http://website.com/error
ErrorDocument 500 http://website.com/error
RewriteEngine On
# HOME
RewriteRule /index http://website.com [R=301,L]
# REDIRECT OLD CONTENT
# PRODUCT GROUPS
RewriteRule /search/+/all+manufacturers/+/cnc/2/10/1/ /products/cncs/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/drive/4/10/1/ /products/drives/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/servo+drive/18/10/1/ /products/servos/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/encoder+%26+resolver/5/10/1/ /products/motors_and_encoders/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/plc/14/10/1/ /products/plcs_and_software/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/computer/3/10/1/ /products/indnettrial_pcs_and_hmis/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/monitor/10/10/1/ /products/monitors/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/robot/16/10/1/ /products/robots/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/power+supply/15/10/1/ /products/power_supplies/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/safety+equipment/17/10/1/ /products/safety_equipment/1 [R=301,L]
RewriteRule /search/+/all+manufacturers/+/comms/34/10/1/ /products/communications/1 [R=301,L]
# CONTACT
RewriteRule /enquire.php /general_enquiry [R=301,L]
# HELP
RewriteRule /help_policies.php /help/policies [R=301,L]
# SITE MAP
RewriteRule /visual_sitemap.php /site_map [R=301,L]
# REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# Old Structure: equipment/<unique-id>/<brand>/<category>/<product-id>/<product-id-slug>/
# New Structure: equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)\+([^-]+)-([^/]+)/([^/]+)/$ http://website.com/equipment/$2-$4_$5_$6/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ http://website.com/equipment/index.php?name=$1&id=$2 [L]
# REMOVE PHP EXTENSIONS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
I'm not sure exactly what makes the difference between an internal and external rewriteOuch! That's a big problem.
# ERROR DOCUMENTS
...
RewriteEngine On
# HOME
...
# REDIRECT OLD CONTENT
# PRODUCT GROUPS
RewriteRule search/+/all+manufacturers/+/cnc/2/10/1/ http://website.com/products/cncs/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/drive/4/10/1/ http://website.com/products/drives/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/servo+drive/18/10/1/ http://website.com/products/servos/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/encoder+%26+resolver/5/10/1/ http://website.com/products/motors_and_encoders/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/plc/14/10/1/ http://website.com/products/plcs_and_software/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/computer/3/10/1/ http://website.com/products/indnettrial_pcs_and_hmis/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/monitor/10/10/1/ http://website.com/products/monitors/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/robot/16/10/1/ http://website.com/products/robots/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/power+supply/15/10/1/ http://website.com/products/power_supplies/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/safety+equipment/17/10/1/ http://website.com/products/safety_equipment/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/comms/34/10/1/ http://website.com/products/communications/1 [R=301,L]
# CONTACT
...
# HELP
...
# SITE MAP
...
# REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# Old Structure: equipment/<unique-id>/<brand>/<category>/<product-id>/<product-id-slug>/
# New Structure: equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)\+([^-]+)-([^/]+)/([^/]+)/$ http://website.com/equipment/$2-$4_$5_$6/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ http://website.com/equipment/index.php?name=$1&id=$2 [L]
# REMOVE PHP EXTENSIONS
... # ERROR DOCUMENTS
ErrorDocument 400 http://website.com/error
ErrorDocument 401 http://website.com/error
ErrorDocument 403 http://website.com/error
ErrorDocument 404 http://website.com/error
ErrorDocument 500 http://website.com/error
RewriteEngine On
# HOME
RewriteRule index http://website.com [R=301,L]
# REDIRECT OLD CONTENT
# PRODUCT GROUPS
RewriteRule search/+/all+manufacturers/+/cnc/2/10/1/ http://website.com/products/cncs/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/drive/4/10/1/ http://website.com/products/drives/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/servo+drive/18/10/1/ http://website.com/products/servos/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/encoder+%26+resolver/5/10/1/ http://website.com/products/motors_and_encoders/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/plc/14/10/1/ http://website.com/products/plcs_and_software/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/computer/3/10/1/ http://website.com/products/indnettrial_pcs_and_hmis/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/monitor/10/10/1/ http://website.com/products/monitors/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/robot/16/10/1/ http://website.com/products/robots/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/power+supply/15/10/1/ http://website.com/products/power_supplies/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/safety+equipment/17/10/1/ http://website.com/products/safety_equipment/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/comms/34/10/1/ http://website.com/products/communications/1 [R=301,L]
# CONTACT
RewriteRule enquire.php http://website.com/general_enquiry [R=301,L]
# HELP
RewriteRule help_policies.php http://website.com/help/policies [R=301,L]
# SITE MAP
RewriteRule visual_sitemap.php http://website.com/site_map [R=301,L]
# REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# Old Structure: equipment/<unique-id>/<brand>/<category>/<product-id>/<product-id-slug>/
# New Structure: equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)\+([^-]+)-([^/]+)/([^/]+)/$ http://website.com/equipment/$2-$4_$5_$6/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ http://website.com/equipment/index.php?name=$1&id=$2 [L]
# REMOVE PHP EXTENSIONS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA] [edited by: Tom_Cash at 2:34 pm (utc) on Mar 21, 2011]
ErrorDocument 404 /error404.php or similar is what you need. search/+/all+manufacturers/+/cnc/2/10/1/ is looking for a URL request like: example.com/search/////////////allllllllllllmanufacturers///////////////cnc/2/10/1/ [edited by: g1smd at 2:42 pm (utc) on Mar 21, 2011]
ErrorDocument 404 /error404.php or similar is what you need.
ErrorDocument 404 error404.php # REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# Old Structure: equipment/<unique-id>/<brand>/<category>/<product-id>/<product-id-slug>/
# New Structure: equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)\+([^-]+)-([^/]+)/([^/]+)/$ http://new.lektronix.net/equipment/$2-$4_$5_$6/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ equipment/index.php?name=$1&id=$2 [L]
# ERROR DOCUMENTS
ErrorDocument 400 http://example.com/error
ErrorDocument 401 http://example.com/error
ErrorDocument 403 http://example.com/error
ErrorDocument 404 http://example.com/error
ErrorDocument 500 http://example.com/error
RewriteEngine On
# HOME
RewriteRule index http://example.com [R=301,L]
# REDIRECT OLD CONTENT
# PRODUCT GROUPS
RewriteRule search/+/all+manufacturers/+/cnc/2/10/1/ http://example.com/products/cncs/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/drive/4/10/1/ http://example.com/products/drives/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/servo+drive/18/10/1/ http://example.com/products/servos/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/encoder+%26+resolver/5/10/1/ http://example.com/products/motors_and_encoders/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/plc/14/10/1/ http://example.com/products/plcs_and_software/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/computer/3/10/1/ http://example.com/products/indnettrial_pcs_and_hmis/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/monitor/10/10/1/ http://example.com/products/monitors/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/robot/16/10/1/ http://example.com/products/robots/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/power+supply/15/10/1/ http://example.com/products/power_supplies/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/safety+equipment/17/10/1/ http://example.com/products/safety_equipment/1 [R=301,L]
RewriteRule search/+/all+manufacturers/+/comms/34/10/1/ http://example.com/products/communications/1 [R=301,L]
# CONTACT
RewriteRule enquire.php http://example.com/general_enquiry [R=301,L]
# HELP
RewriteRule help_policies.php http://example.com/help/policies [R=301,L]
# SITE MAP
RewriteRule visual_sitemap.php http://example.com/site_map [R=301,L]
# REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# Old Structure: equipment/<unique-id>/<brand>/<category>/<product-id>/<product-id-slug>/
# New Structure: equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)\+([^-]+)-([^/]+)/([^/]+)/$ http://example.com/equipment/$2-$4_$5_$6/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ equipment/index.php?name=$1&id=$2 [L]
# REMOVE PHP EXTENSIONS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA] RewriteRule index http://example.com [R=301,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L] # REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# Old Structure: equipment/<unique-id>/<brand>/<category>/<product-id>/<product-id-slug>/
# New Structure: equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([a-zA-Z0-9_-]+)/([^/]+)/$ http://new.lektronix.net/equipment/$2-$4/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ equipment/index.php?name=$1&id=$2 [L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L] Once the redirection and rewriting stuff is working, do not forget to re-address the ErrorDocument problem. Using a protocol and domain name in ErrorDocument directives results in a server status of 302 being returned for ALL erroneous requests. To be clear, when requesting a bogus URL, Googlebot will see a 302 redirect when you want it to see a 404-Not Found or 410-Gone. This is nothing short of SEO suicide...
ErrorDocument 400 /error
ErrorDocument 400 error
ErrorDocument 400 /error.php
ErrorDocument 400 error.php # REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# This one works for urls like this: equipment/16955/siemens/plc/6es5+322-0aa11/6es5322011/
# Old Structure: equipment/<unique-id>/<brand>/<category>/<product-id>/<product-id-slug>/
# New Structure: equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)\+([^-]+)-([^/]+)/([^/]+)/$ http://example.com/equipment/$2-$4_$5_$6/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ equipment/index.php?name=$1&id=$2 [L]
# REDIRECT OLD EQUIPMENT URLS TO NEW ONES
# This one works for urls like this: equipment/23049/lust/servo+drive/mc7408/mc7408/
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)/([^/]+)/$ http://example.com/equipment/$2-$4/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ equipment/index.php?name=$1&id=$2 [L] Although there are 63 000 products, there might only be a few rule formats required.
Maybe this is the time to tighten up exactly what you allow in a URL?
The problem comes from URLs where something "changes" e.g. where "-" becomes "+" or vice versa. That is why a single "generic" rule may be "too difficult".
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/(.+)/([^/]+)/$ http://www.example.com/equipment/$2-$4/$1 [R=301,L]
RewriteRule ^equipment/(.+)/([0-9]+)$ equipment/index.php?name=$1&id=$2 [L] (.+) would be a better choice than ([^/]+) here? What processes led to that decision?