ahrefs site auditing, reports a redirect chain that I cant't see. Surely, only the first ruleset should be activated. What's causing this ?



Redirect chain URLs


my .htaccess is

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.software$ [NC]
RewriteRule ^(.*)$ https://example.software%{REQUEST_URI} [R=301,L,QSA]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.online$ [NC]
RewriteRule ^(.*)$ https://example.online%{REQUEST_URI}  [R=301,L,QSA]

RewriteCond %{HTTP_HOST} ^example\.online$ [NC]
RewriteRule ^(.*)$ https://other.example.software%{REQUEST_URI}  [L,QSA]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.app$ [NC]
RewriteRule ^(.*)$ https://example.app%{REQUEST_URI}  [R=301,L,QSA]

RewriteCond %{HTTP_HOST} ^example\.app$ [NC]
RewriteRule ^(.*)$ https://apps.example.software%{REQUEST_URI}  [L,QSA]

# remove www from https
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

#force html extn
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

#For existing publishing
RewriteCond %{HTTP_HOST} ^example.software$ [NC]
RewriteRule ^(download)/([^/]+)$ https://example.software?mode=file&name=$2 [L]
  • What is the redirect chain being reported? Are you suggesting that http://www.example.software/ is being redirected to https://www.example.software/? (Which isn't possible with the directives as posted.) FWIW I don't see a "redirect chain" in the directives you've posted, except for the "other" hostnames: www.example.online and www.example.app when requested over HTTP.
    – MrWhite
    Jan 9 at 23:22
  • Thats what the report is saying that there are two redirects. the first to https with the www and then to the correct one. Oh well, time to report it as a bug to ahrefs then Jan 10 at 1:02
  • If you test the request yourself do you see a redirect chain?
    – MrWhite
    Jan 10 at 16:51
  • @RohitGupta Sounds like an ahrefs issue to me. No audit tool that is browser based is going to work very well in my opinion. I prefer something like sitebulb or screaming frog that will allow you to tell it how many logical processors to crawl with. Jan 10 at 23:14
  • @MikeCiffone I did install sitebulb earlier, but it just starts up and then minimises the window. I was about to remove it :-) Jan 11 at 0:55

2 Answers 2


In response to MrWhite's comment, I found out how to see the redirect chain in the browser mimiced what ahrefs was saying.

When I took out the ruleset to remove the www, it works fine.

#remove www from https
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

I would still like to remove www.

Further testing shows that www should be removed as the certificate isnt valid for www in the url. And actually deref.link says exactly this.

400 Error!
SSL: no alternative certificate subject name matches target host name 'www.example.software'
  • "When I took out the ruleset to remove the www, it works fine" - Although that doesn't make sense given the directives in the question. "the certificate isnt valid for www" - In that case, browser security will block the request and it won't even reach your server. (Unless you dismiss the warning and accept an invalid cert?)
    – MrWhite
    Jan 14 at 20:06

For your non-www you forgot RewriteCond %{HTTPS} =on

So try:

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] 
RewriteCond %{HTTPS} =on 
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
  • You are correct, but I still get the same result. I have to look at other things, its not making sense Jan 11 at 0:53
  • It would be nice to combine it into one. To remove the www and to force https. My attempts havent worked. I can see generic ones everywhere, but I cant use that for now. Also I found a flag in cpanel to force https, which I have removed. It didnt make any changes to htaccess, so it must have been setting it elsewhere. ahrefs now returns clean. Jan 11 at 1:44
  • Try to replicate this and send the output of tail -n 20 /var/log/apache2/error.log Jan 11 at 6:30
  • "For your non-www you forgot RewriteCond %{HTTPS} =on" - Why? You would normally want to remove www from both HTTP and HTTPS requests. However, at this point in the config file the request would already be HTTPS (either by the first rule or because the initial request was HTTPS), so the condition would be superfluous anyway (at least for the stated request). (Although it transpires that the SSL cert doesn't cover the www subdomain so the rule wouldn't be processed anyway without at least dismissing a browser warning.)
    – MrWhite
    Jan 14 at 20:29
  • 1
    You are correct, which is probably why I had removed the https check. I guess it makes sense to do the www check first. I do realise that there are issues with the subdomains, but this wasnt about a subdomain. And I wanted to put up the whole redirection segment of the htaccess, to make sure I hadnt stuffed it up. I believe now that the flag that the host's employees had put on in cpanel "Enforce https", when they installed the certificate, was interfering. When I removed it, it didnt make any changes to htaccess and things are working. Jan 14 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.