apache2 config: enable access to /server-status while having catch-all 301 redirects

Posted on

apache2 config: enable access to /server-status while having catch-all 301 redirects – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, mod-rewrite, , , .

I have an Apache2 server with various virtual servers running. For SEO purposes, anything that does not match www.mydomain.com is automatically redirected to www.mydomain.com.

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

This is working fine but I want to monitor status of the apache server by calling http://localhost/server-status?auto

The problem is that this is redirecting to http://www.mydomain.com/server-status which is not a valid URL. What additional redirect can I add to avoid this problem? Or is there some other way this can be tackled?

Solution :

Try:

RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com$1 [R=301,L]

Leave a Reply

Your email address will not be published.