Tag Archive: apache

append and prepend script with apache

Sometimes we need to run a script in our localhost (or maybe in production) but we don’t want to edit our application to test the current environment. To solve this problem we can just add the file via apache virtual host configuration.

So go on and edit your virtual host, and add this line to the <Directory> directive.

To execute at the end:

1
php_value auto_append_file "/Users/walter/workspace/append.php"

To execute before everything:

1
php_value auto_prepend_file "/Users/walter/workspace/prepend.php"

Don’t forget to restart apache before reloading the app.

htaccess redirect all subdomain except one

I needed a rule to redirect all subdomain in my domain except one specified subdomain, to do that I use those few lines in my .htaccess file

1
2
3
4
5
6
7
8
<IfModule mod_rewrite.c>
  DirectoryIndex index.php
  RewriteEngine on

  RewriteCond %{HTTP_HOST} !noredirect.waltertavares.pt$ [NC]
  RewriteCond %{HTTP_HOST} (.*).waltertavares.pt$ [NC]
  RewriteRule ^(.*)$ http://www.waltertavares.pt/$1 [L,R=301]
</IfModule>

Of course you can skip redirection on a full list of subdomains by duplicating the line

1
2
3
  RewriteCond %{HTTP_HOST} !noredirect.waltertavares.pt$ [NC]
  RewriteCond %{HTTP_HOST} !no-redirect.waltertavares.pt$ [NC]
  RewriteCond %{HTTP_HOST} !real-sub-domain.waltertavares.pt$ [NC]