.htaccess conditional IF localhost

I have a kirby installation on SiteGround on www.namesurname.com
I added the subdomain resume.namesurname.com that redirects to www.namesurname.com/resume.

SiteGround added the following rules at the end of the .htaccess on the server. I copied the same lines into my local .htaccess, so the two files are identical and git doesn’t find any conflict.

Problem is when I open the local copy of the website, I receive a blank error page.

Is there a way to put an IF statement, so that if the website is running on server, the lines get processed. If it is running on localhost, the lines are skipped?

# SiteGround redirect for Name Surname
AddHandler application/x-httpd-php70 .php .php5 .php4 .php3
RewriteCond %{HTTP_HOST} ^resume\.namesurname\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.resume\.namesurname\.com$
RewriteRule ^/?$ "http\:\/\/www\.namesurname\.com\/resume" [R=301,L]

You should remove the first line (AddHandler). This one is not specific to the redirect, but sets which PHP version to use (which does not make any sense for a simple redirect).

After that, the rule should work on your local dev host as well and be ignored there. The RewriteCond rules are basically if rules. :wink:

Thanks! It works :slightly_smiling:

Actually I found out SiteGround needs the following line into the .htaccess

AddHandler application/x-httpd-php70 .php .php5 .php4 .php3

That line specify which version of PHP to use for that specific folder on the server.

If I keep the above line in my localhost installation, it returns me a white page (and downloads index.php).

Is there anything else I can do to keep that line in both .htaccess, but ignore when running it on localhost?


Apache 2.4 has an if directive: https://blogs.apache.org/httpd/entry/new_in_httpd_2_4. So if you are on 2.4 you can use that, something like

<If "req('Host') != 'localhost'">
   //do stuff