Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
snippets
.htaccess / mod_rewrite
404 header
Ajax response page
Basic HTTP Auth
Column display sans near-empty columns
JavaScript favelets/bookmarklets
misc php stuffs
php tricks
8
found
auth
Name:
Category: snippets
Body:
# this one needs split into an Apache section or something.. # First: Don't forget to put the damn RewriteEngine On # at the top. Kthxby. (srsly, I forget this EVEN when I've just seen it *here*) # Turn on logging! For Great Debugging! It's .. Useful! RewriteLog /var/log/apache2/rewrite.log # 9 is highest, and throws everything out there, line by line. Turn off when no longer needed, it's "expensive" RewriteLogLevel 9 # useful condition to only trigger the rewrites for your IP address, when testing RewriteCond %{REMOTE_ADDR} 12.34.56.78 # if file or folder doesn't exist, pass it to the index file as $_GET['q'] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 # Like the above, if file or folder doesn't exist, pass it to the index file as $_GET['q'] # Also do this inside the config directory, rewriting to the config's index.php file # - note the $1 "dollar-one" in front of index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(config/)?(.*)$ $1index.php?q=$2 [QSA] # copied from somewhere, redirects http://example.com/yadda to http://www.example.com/yadda # with a moved permanently header RewriteCond %{HTTP_HOST} !^www.example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] # IF the file could not be found AND IF there are uppercase characters in the requested URI, redirect to its # lowercase version (and if /that/ can't be found, well, 404) # NB: RewriteMap only works in VHost or similar, /not/ htaccess. # NB2: %{DOCUMENT_ROOT} is needed in VHost context. (htaccess looks from site root, VHost deals from server root) RewriteMap lowcase int:tolower RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} [A-Z] RewriteRule ^(.*)$ ${lowcase:$1} [R=301,L] # Force downloads of pdfs, mp4, or whatever <FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
Footer