.htaccess

==Basic Auth== AuthName "Login" AuthGroupFile /dev/null AuthUserFile /domains/....../.htpasswd AuthType Basic require valid-user


== redirect ==
<code apache>
RewriteEngine On

##############################
# redirect /doku.php?id=xxx  #
###############################
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^doku\.php$ http://wiki.companje.nl/%1? [R=302,L]
##############################

##############################
# redirect if file not found #
##############################
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://wiki\.companje\.nl/$1 [L,R=301]
#############################

===== Examples in Dutch ===== http://andrescholten.nl/voorbeelden-veel-gebruikte-htaccess-regels/

===== internal server error while using ‘Header add’ ===== enable Apache’s headers module: sudo a2enmod headers && sudo service apache2 restart

=====Access-Control-Allow-Origin===== http://enable-cors.org/server_apache.html or put this header in your php script: header('Access-Control-Allow-Origin: *');



=====show php errors=====
<code apache>
# don't supress php errors
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

=====disable cache===== Header append Cache-Control "no-cache"


=====mod_rewrite cheat sheet=====
* http://www.cheatography.com/davechild/cheat-sheets/mod-rewrite/

=====download as attachment=====
<code apache>
<FilesMatch "\.(mov|mp4)$">
  Header set Content-Disposition attachment
</FilesMatch>

=====htaccess auth===== AuthType Basic AuthUserFile FOLDER/.htpasswd

require valid-user

=====create SHA encrypted password for htpasswd=====
```bash
htpasswd -s FOLDER/.htpasswd USERNAME

=====redirect subdomain to other url===== RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com RewriteRule (.*) YOUR_URL [R=301,L]


with subfolder in query: (place this before the code above)

<code apache>
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.domain\.com
RewriteCond %{REQUEST_URI} ^/lijst
Rewriterule ^(.*)$ http://otherdomain.com [L]

=====htaccess ignored?===== set ‘AllowOverride’ to ‘All’ in httpd.conf within ...

=====examples in dutch=====

  • http://andrescholten.net/voorbeelden-veel-gebruikte-htaccess-regels/

=====redirect to other domain with keeping folder===== RewriteCond %{HTTP_HOST} =doodle3d.com RewriteRule (.*) http://www.doodle3d.com/$1


=====redirect subdomain=====
<code Apache>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^kc\.doodle3d\.nl$ [NC]
RewriteRule (.*) http://kunstcentraal.doodle3d.nl [R]

=====serve .csv as text mime type===== AddType text/plain .csv


=====Enable directory listing=====
<code Apache>
Options +Indexes

=====Disable directory listing===== Options -Indexes


=====Redirect if URL equals HTTP_HOST=====
<code Apache>
RewriteRule ^$ /nl [R=301,L]

=====Unprotect a subdir of a htaccess password-protected directory===== create a .htaccess in the subfolder with this in it: Satisfy any


=====change max upload in PHP/ upload_max_filesize=====
edit your .htaccess:
<code Apache>
php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200