Hi,

    I have a rewrite that's creating a loop because the origin is
    contained in the final destination. I know it then is processed
    again by the .htaccess in the document root, but I don't
    understand why or how to stop it. What's the solution here?

    RewriteRule
    ^/features/linux-malware-the-truth-about-this-growing-threat$
    
https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat-updated
    [L,R=301,END]

    I've tried variations of the above but it always creates a loop.

    $ wget -O /dev/null
    
https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat
    2>&1|grep -E 'Location|HTTP'
    HTTP response 302
    
[https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat]
    HTTP response 301
    
[https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat-updated]
    HTTP response 200  [https://linuxsecurity.com//features]

    Thanks,
    Dave



If you don't depend on mod_rewrite for anything else, I would recommend using RedirectMatch instead.

That rule on its own won't loop, unless you have other conflicting directive or rewrite rules.

If you must use mod_rewrite, then enabling the rewrite log will help you pinpoint the source of the loop.

Are you suggesting RedirectMatch because using RewriteRule when the origin is a subset of the destination is a known problem?

Here's what the rewrite log trace looks like:

rewrite '/features/linux-malware-the-truth-about-this-growing-threat' -> 'https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat-updated' explicitly forcing redirect with https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat-updated escaping https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat-updated for redirect redirect to https://linuxsecurity.com/features/linux-malware-the-truth-about-this-growing-threat-updated [REDIRECT/301] init rewrite engine with requested uri /features/linux-malware-the-truth-about-this-growing-threat-updated

it then appears to loop through the htaccess:

rewrite 'features/linux-malware-the-truth-about-this-growing-threat-updated' -> 'index.php'
add per-dir prefix: index.php -> /var/www/linuxsec/html/index.php
trying to replace prefix /var/www/linuxsec/html/ with /
internal redirect with /index.php [INTERNAL REDIRECT]
init rewrite engine with requested uri /index.php

Thanks,
Dave

Reply via email to