Forum Moderators: phranque
301'ing over 50 thousand pages
www.example.com/folder/unique-id/manufacturer/product/product-id/product-id-slug/
/equipment/4009/siemens/plc/6es5+943-7ua11/6es59437u11/ gets rewritten to the internal query index.php?name=folder/unique-id/manufacturer/product/product-id/product-id-slug/
/equipment/4009/siemens/plc/6es5+943-7ua11&id=6es59437u11 here? example.com/142355/my-great-product and use only 142355 to pull the product from the databse. example.com/142355/do-not-buy-this-trash. RewriteRule ^([0-9]+)/(.*) /index.php?id=$1&product=$2 [L] and follow several simple steps. example.com/142355/my-great-product example.com/142355/my-great-p example.com/142355/my-great-product"<br/></a example.com/142355 example.com/kitchen/saucepans/17234 and is rewritten to /index.php?cat=$1&subcat=$2&prod_ID=$3. example.com/shirts/mens/17234, the page will show me the saucepans set with breadcrumb links to the shirts category, and a page title of "shirts : mens : 5 piece saucepan set". [edited by: g1smd at 10:43 am (utc) on Mar 9, 2011]
RewriteRule ^([^/]+)/([^_]+)_([^/]+)/([^/]+)/([^/]+)/([^.]+)$ http://www.example.com/$6/$2-$5 [R=301,L] RewriteRule ^(0-9+)/([^-]+)-(.*) /index.php?id=$1&manu=$2&prod=$3 [L] www.example.com/153773/this-great-acme-widget links out to www.example.com/widgets, www.example.com/acme, www.example.com/under-50-quid and www.example.com/sale-items where the single canonical product URL without category is listed in the links from those categories back to the product page itself.
[^/] means "NOT a slash", and the plus means "one or more times", so ([^/]+)/ matches everything up to the first slash and puts it in $1. You have both the slash and underscore separators in the old URL to help with the pattern matching.
RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ http://www.website.com/equipment/$2-$4/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+) /equipment/index.php?name=$1&id=$2 [L]
# Externally redirect requests for old URLS of the form
# /equipment/<unique-id>/<brand>/<product>/<product-id>/<product-id-slug>/ to new URLs of the form
# /equipment/<brand>-<product-id>/<unique-id>
RewriteRule ^equipment/([^/]+)/([^/]+)/[^/]+/([^/]+)/[^/]+/$ http://www.example.com/equipment/$2-$3/$1 [R=301,L]
equipment/ from all of the RegEx patterns (only from the patterns) in that example, and make sure the redirected-to URL does include the full path of the new location. RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ http://website.net/equipment/$2-$3/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ http://website.net/equipment/index.php?name=$1&id=$2 [L] Redirect and RewriteRule code in the same website. Once you have used RewriteRule for any of your rules, you must use it for all of your Rules. RewriteRule ^thispage http://www.example.com/thatpage [R=301,L] Redirect 301 /thispage http://www.example.com/thatpage RewriteRule gives you more control because Redirect automatically re-appends the rest of the original path on to the end of the new URL. RewriteRule for both external redirects and internal rewrites.
/equipment/4009/siemens/plc/6es5+943-7ua11/6es59437u11/ /equipment/siemens-6es5_943_7ub21/2067 RewriteRule ^equipment/([^/]+)/([^/]+)/([^/]+)/([^+]+)\+([^-]+)-([^/]+)/([^/]+)/$ http://www.example.com/equipment/$2-$4_$5_$6/$1 [R=301,L]
RewriteRule ^equipment/([a-zA-Z0-9_-]+)/([0-9]+)$ http://website.net/equipment/index.php?name=$1&id=$2 [L]
# 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
# REMOVE PHP EXTENSIONS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
# HOME
redirect 301 /index http://website.com
# REDIRECT OLD CONTENT
# PRODUCT GROUPS
redirect 301 /search/+/all+manufacturers/+/cnc/2/10/1/ /products/cncs/1
redirect 301 /search/+/all+manufacturers/+/drive/4/10/1/ /products/drives/1
redirect 301 /search/+/all+manufacturers/+/servo+drive/18/10/1/ /products/servos/1
redirect 301 /search/+/all+manufacturers/+/encoder+%26+resolver/5/10/1/ /products/motors_and_encoders/1
redirect 301 /search/+/all+manufacturers/+/plc/14/10/1/ /products/plcs_and_software/1
redirect 301 /search/+/all+manufacturers/+/computer/3/10/1/ /products/indnettrial_pcs_and_hmis/1
redirect 301 /search/+/all+manufacturers/+/monitor/10/10/1/ /products/monitors/1
redirect 301 /search/+/all+manufacturers/+/robot/16/10/1/ /products/robots/1
redirect 301 /search/+/all+manufacturers/+/power+supply/15/10/1/ /products/power_supplies/1
redirect 301 /search/+/all+manufacturers/+/safety+equipment/17/10/1/ /products/safety_equipment/1
redirect 301 /search/+/all+manufacturers/+/comms/34/10/1/ /products/communications/1
# CONTACT
redirect 301 /enquire.php /general_enquiry
# HELP
redirect 301 /help_policies.php /help/policies
# SITE MAP
redirect 301 /visual_sitemap.php /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]