Home > Mobile >  Accuracy of htaccess testing tools
Accuracy of htaccess testing tools

Time:10-23

I trying to improve my understanding of htaccess rewrite rules and used a couple of online testing tools to verify a simple rewrite I did, but I don't understand why the returned url is repeated. I'm questioning if my rule is wrong of if there is something inherently wrong with this tool?

All I am trying to do is redirect all requests to a .com domain to the same page on a .com.au domain.

RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule .? "https://domain.com.au%{REQUEST_URI}" [L,R=301]

So as I understand, this says:

  • Conditions: If the host is domain.com OR www.domain.com
  • Rule: match anything or nothing as the requested uri and redirect to https://domain.com.au/whatever-the-request-uri-is

But when I test this using https://htaccess.madewithlove.be for example, the returned url repeats like https://domain.com.au/bloghttps://domain.com.au/bloghttps://domain.com.au/blog... However on the web server it appears to work fine.

The other rule I tried was:

RewriteRule ^(.*)$ https://domain.com.au/$1 [R=301,L]

And this returns a single correct result using the testing tool, but I read that it's preferable to use the server variables.

So is there something wrong with my first rule or is that testing tool broken?

CodePudding user response:

This works according to my tests:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^ https://example.com.au%{REQUEST_URI} [L,R=301]

I am currently unable to explain why your own attempt does not, though. Sorry! I have the impression that this is indeed a bug inside the test utility, assuming that you used https://htaccess.madewithlove.be/ ...

  • Related