How to trace Apache 301 Moved Permanently?

21,486

Solution 1

It's not necessarily Apache's configuration that's doing this - is Apache handing the request off to a dynamic content generator?

Look for two things in your Apache config; Redirect, and RewriteRule directives that have an R flag. If those aren't in place, then Apache isn't doing the redirect (with the exception of /directoryname redirecting to /directoryname/, but that doesn't sound like the case here), and you'll need to look at the dynamic code that Apache's handing the request to.

Solution 2

Thanks for the above answer and it points me to the right direction. In my case, the 301 redirect is caused by a rewrite rule for the whole site.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^voicent.com
RewriteRule ^/(.*)$ http://www.voicent.com/$1 [L,R=301]

The above rule forces the use of canonical host name. It makes every url starts with www.domain.com, instead of domain.com. You can further verify this in the apache access log.

Share:
21,486

Related videos on Youtube

Suzan Cioc
Author by

Suzan Cioc

Not to be offended

Updated on September 18, 2022

Comments

  • Suzan Cioc
    Suzan Cioc over 1 year

    I have one virtual host on my machine, which I am accessing localy. I am running apache2 under windows 7.

    When accessing this host, I see in Fiddler, that server redirects browser to different remote site with response

    301 Moved Permanently
    

    But I am absolutely can't find where is it configured. I search all .htaccess files for the URL of target site, all files in the given virtual host for this URL, all Apache directory...

    How to trace what causes Apache to do this redirection?

  • Incisor
    Incisor over 9 years
    Thanks Shane, I was pulling my hair out trying to figure out why my post was getting lost with a 301 redirect. It turned out to be /directoryname redirecting to /directoryname/.... missed the obvious. Thanks!