Rhino
Rhino

Reputation: 39

Last redirect in htaccess is too many?

Trying to determine why only the last redirect returns a "Too Many Redirects" error when visiting the page. If I add anymore after the last one they all get the same error when visiting the pages.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^myhrc.biz$ [OR]
RewriteCond %{HTTP_HOST} ^www.myhrc.biz$ [OR]
RewriteCond %{HTTP_HOST} ^houstonroofcontractor.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.houstonroofcontractor.com$ [OR]
RewriteCond %{HTTP_HOST} ^bestroofertx.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.bestroofertx.com$ [OR]
RewriteCond %{HTTP_HOST} ^roofingcompanyhoustontexas.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.roofingcompanyhoustontexas.com$ [OR]
RewriteCond %{HTTP_HOST} ^houstonroofingreviews.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.houstonroofingreviews.com$ [OR]
RewriteCond %{HTTP_HOST} ^houstonroofingonline.co$ [OR]
RewriteCond %{HTTP_HOST} ^www.houstonroofingonline.co$ [OR]
RewriteCond %{HTTP_HOST} ^houstonroofingonline.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.houstonroofingonline.net$ [OR]
RewriteCond %{HTTP_HOST} ^houstonroofingonline.info$ [OR]
RewriteCond %{HTTP_HOST} ^www.houstonroofingonline.info$ [OR]
RewriteCond %{HTTP_HOST} ^houstonroofingonline.com$
RewriteRule (.*)$ http://www.houstonroofingonline.com/$1 [R=301,L]
ErrorDocument 404 http://www.houstonroofingonline.com/404.html
RedirectMatch 301 ^/residential http://www.houstonroofingonline.com/residential-roofing-houston.html
RedirectMatch 301 ^/about-us http://www.houstonroofingonline.com/houston-roofing-company.html
RedirectMatch 301 ^/residential/insurance-claims http://www.houstonroofingonline.com/roof-insurance-claims-houston.html
RedirectMatch 301 ^/residential/free-roof http://www.houstonroofingonline.com/free-roof-insurance-claim.html
RedirectMatch 301 ^/residential/storm-damage http://www.houstonroofingonline.com/storm-damage-roof-repair-houston.html
RedirectMatch 301 ^/residential/roof-inspection http://www.houstonroofingonline.com/free-roof-inspection-houston.html
RedirectMatch 301 ^/residential/roof-repair http://www.houstonroofingonline.com/roof-repair-houston.html
RedirectMatch 301 ^/commercial http://www.houstonroofingonline.com/commercial-roofing-houston.html
RedirectMatch 301 ^/contact-us http://www.houstonroofingonline.com/contact.html
RedirectMatch 301 ^/blog http://www.houstonroofingonline.com/houston-roofing-blog.html
RedirectMatch 301 ^/roofing-system-complexities http://www.houstonroofingonline.com/roofing-systems.html
RedirectMatch 301 ^/how-to-select-roof http://www.houstonroofingonline.com/how-to-select-a-roof.html
RedirectMatch 301 ^/your-roof-as-a-selling-tool http://www.houstonroofingonline.com/your-roof-as-a-selling-tool.html

Upvotes: 0

Views: 39

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

Your last Redirect is causing a Redirect Loop error /Too many Redirect error. Let's see why this is happening :

RedirectMatch 301 ^/your-roof-as-a-selling-tool http://www.houstonroofingonline.com/your-roof-as-a-selling-tool.html

Actually , The pattern and the destination path of your RedirectMatch are identical.

Pattern : ^/your-roof-as-a-selling-tool*

Destination url : http://www.houstonroofingonline.com/your-roof-as-a-selling-tool.html

When you request example.com/your-roof-as-a-selling-tool your RedirectMatch redirects the url to http://www.houstonroofingonline.com/your-roof-as-a-selling-tool.html in the first round. And in the second round http://www.houstonroofingonline.com/your-roof-as-a-selling-tool.html matches the pattern and Redirects to itself.

To avoid this multiple redirect behavior you need to fix the pattern so it doesn't match the destination path. Simply add a regex end of string character $ at the end so that it can only match a specific uri /your-roof-as-a-selling-tool not ...tool.html .

RedirectMatch 301 ^/your-roof-as-a-selling-tool$ http://www.houstonroofingonline.com/your-roof-as-a-selling-tool.html

Upvotes: 1

Related Questions