Redirect rules and condition: why should I repeat the condition every time?

Discussion in 'Apache' started by seoinitaly, Oct 15, 2010.

  1. #1
    Hi All,

    I'm not an Apache expert and I rarely use the redirect rules, however I did my best to read the documentation and look for examples that would have been able to provide me an answer without success.

    In my .htaccess file I implemented the following rules (I paste just the first 4)

    RewriteCond %{HTTP_HOST} ^andreamoro.eu$ [OR]
    RewriteCond %{HTTP_HOST} ^www.andreamoro.eu$
    RewriteRule ^contactme\/?$ "http\:\/\/www\.andreamoro\.co\.uk\/contactme\/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^andreamoro.eu$ [OR]
    RewriteCond %{HTTP_HOST} ^www.andreamoro.eu$
    RewriteRule ^about\-andrea\-moro\/?$ "http\:\/\/www\.andreamoro\.co\.uk\/about\-andrea\-moro\/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^andreamoro.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.andreamoro.co.uk$
    RewriteRule ^contattami\/?$ "http\:\/\/www\.andreamoro\.eu\/contattami\/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^andreamoro.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.andreamoro.co.uk$
    RewriteRule ^biografia\/?$ "http\:\/\/www\.andreamoro\.eu\/biografia\/" [R=301,L]

    They works fine if they are written in this way.

    As there are two groups of conditions based on the incoming host, I read that it was possible group the rules underneath the same condition. So I tried and published the file in the following way

    RewriteCond %{HTTP_HOST} ^andreamoro.eu$ [OR]
    RewriteCond %{HTTP_HOST} ^www.andreamoro.eu$
    RewriteRule ^contactme\/?$ "http\:\/\/www\.andreamoro\.co\.uk\/contactme\/" [R=301,L]
    RewriteRule ^about\-andrea\-moro\/?$ "http\:\/\/www\.andreamoro\.co\.uk\/about\-andrea\-moro\/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^andreamoro.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.andreamoro.co.uk$
    RewriteRule ^contattami\/?$ "http\:\/\/www\.andreamoro\.eu\/contattami\/" [R=301,L]
    RewriteRule ^biografia\/?$ "http\:\/\/www\.andreamoro\.eu\/biografia\/" [R=301,L]

    As soon as the file is live, the rules continue to work as they are meant but each single rules fall into a invisible loop chain that with a browser like firefox you generally don't see it.
    I discovered through chrome and double checked with an header checker, and that's true. In the above way I got 5 redirects to arrive to the final destination and I'm not able to guess why. Apart from any perfomance downside, this is very detrimental in a SEO condition.

    My website is relatively small, but I have another where I require the above pattern with many hosts conditions. And this web site requires 300 rules or more. If I need to replicate the condition per each rules, this .htaccess file will became so big and unmanageable, without considering that it can negatively effect the performance of the server.

    Can you give me a clue on this, please?

    Cheers
    Andrea
     
    seoinitaly, Oct 15, 2010 IP