User Tools

Site Tools


Sidebar



htaccess

.htaccess

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

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

# 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

download as attachment

<FilesMatch "\.(mov|mp4)$">
  Header set Content-Disposition attachment
</FilesMatch>

htaccess auth

AuthType Basic
AuthUserFile FOLDER/.htpasswd
<limit GET POST>
  require valid-user
</limit>

create SHA encrypted password for htpasswd

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)

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 <Directory>…

examples in dutch

redirect to other domain with keeping folder

RewriteCond %{HTTP_HOST} =doodle3d.com
RewriteRule (.*) http://www.doodle3d.com/$1

redirect subdomain

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

Options +Indexes

Disable directory listing

Options -Indexes

Redirect if URL equals HTTP_HOST

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:

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200
htaccess.txt · Last modified: 2015/09/02 11:12 by rick