Support

Admin Tools

#31705 Redirecting non-www to www results in 302 status code

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by on Friday, 04 October 2019 17:17 CDT

jorlan
Hi,

In AdminTools .htaccess maker, we've enabled Redirect non-www to www. By chance, we noticed that this results in a 302 status code from the site (as reported by the online tool isitup.org) when visiting the non-www url and a 301 when visiting the www url.

With redirecting disabled - and with the Joomla core .htaccess file - both www and non-www return a 301 code.

With redireting enabled, we noticed that the .htaccess code contains this line:

RewriteRule ^(.*)$ http%2://www.%{HTTP_HOST}/$1 [R,L]


We could of course change the last part to "[R=301,L]", manually / directly in the .htaccess file, but I suppose that this might be overwritten when using .htaccess maker in the future?

Would it be possible to add this to the AdminTools functionality? Or is there a reason why you didn't add this in the first place?

And we are a bit surprised by the fact that with Joomla core .htaccess we get a 301 and not a 200 response. I am aware that this is not part of your service, but if you happen to know how / why this is happening we'd be happy to learn more about it.


Kind regards

nicholas
Akeeba Staff
Manager
The functionality you request exists since about eight years ago. However, whether it's enabled depends on your Apache version and whether your host lets us detect it.

There is a very good reason for it, too. Apache 1.x and 2.0 as well as LiteSpeed do not support status codes in redirects such as [R=301]. If you try to write a .htaccess rule with a redirect status code these versions of Apache will throw a 500 Internal Server Error and your site won't load anymore.

What we do is try to detect the Apache version using the SERVER_SOFTWARE environment variable. If it contains the version as it should e.g. "Apache/2.4.20", we can safely detect the Apache version and enable the redirect HTTP access code feature for Apache 2.4. If the server software string is empty, does not contain a version or indicates it is LiteSpeed we disable this feature.

Please ask your host whether they are using Apache 2.2 or later. If they are not using Apache or they use an older version of Apache you will need to ask them to switch you to Apache 2.2 or later. If they are already using Apache 2.2 or later please ask them to restore the SERVER_SOFTWARE environment variable to its default, including the version number (it can be customised).

Please note that we will not provide a user-accessible control for this feature. Doing that instead of auto-detecting the setting makes it harder for users to successfully set up .htaccess maker. Furthermore and most importantly, search engines no longer care about HTTP 301 vs 302. The only remaining utility of that feature is in the context of HTTP to HTTPS redirection but a. HSTS does it better (and when you enable HSTS we always use HTTP 301 to permanently redirect first time visitors to HTTPS) and b. in a few short years HTTPS will be a requirement, not an afterthought. But I digress. The end result is that after careful consideration I have decided not to add a user accessible toggle switch for R=301 in the .htaccess Maker.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

jorlan
Hi Nicholas,

Thanks for your extensive reply. I know that one of the sites where we've encountered this situation runs on Apache 2.4.39, so we'll have a look into the SERVER_SOFTWARE variable. I'm not sure about the other site, we'll look into that as well.


Kind regards,

System Task
system
This ticket has been automatically closed. All tickets which have been inactive for a long time are automatically closed. If you believe that this ticket was closed in error, please contact us.

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!