Alpha
Share and Organize Code
login register
HotNewTop
F.A.Q.
1. To begin adding code first register.
2. Create your own tags for code that you add.
3. To see your own code click Me, to see all code click Everyone, or filter by people rob.
4. To follow a user, click on their username, rob and hit follow.
5. Add other code to your library by clicking the
button near the code titles (note that you can not edit these codes).
6. To create a copy of a code that you can edit use fork.
7. If you can't find your code, double check your filter settings as you can filter by Category, User and Tag simultaneously.
8. Add comments to a code by clicking on it's title or the comments link underneath it.

Prevent Hotlinking (plain)

1
2
3
4
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$  
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/ .*$ [NC]  
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
comments (1) flag fork

Set up a Default Image (plain)

1
2
3
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^images/.*\.jpg$ /images/default.jpg [L]
comments (1) flag fork

Strip Query Strings (plain)

1
2
3
RewriteEngine On
RewriteCond %{QUERY_STRING} example=  
RewriteRule (.*) http://www.domain.com/$1? [R=301]
comments (1) flag fork

Block User Agents (plain)

1
2
3
4
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} UserAgentA [OR]  
RewriteCond %{HTTP_USER_AGENT} UserAgentB
RewriteRule ^/* http://www.domain.com/sorry.html [L]
comments (1) flag fork

Block a Specific IP Address (plain)

1
2
3
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^(A\.B\.C\.D)$
RewriteRule ^/* http://www.domain.com/sorry.html [L]
comments (1) flag fork

Redirect Request For domain.com To www.domain.com (plain)

1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]
comments (1) flag fork

Redirect Anything That Starts With a Specific Pattern to Index (plain)

1
2
3
RewriteEngine On
RewriteCond $1 !^(index\.php|images|css|javascript)
RewriteRule ^(.*)$ /index.php/$1 [L]
comments (1) flag fork

Temporary Maintenance Page (plain)

1
2
3
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [L]
comments (1) flag fork

Relaxing Security in a Subdirectory (plain) (source)

1
2
3
4
5
6
7
8
9
10
<Directory /var/www>
    Satisfy All
    AuthUserFile /etc/apache/htpasswd
    Require valid-user
</Directory>

#put in .htaccess file in any sub directory you want to allow access to.
Satisfy Any
Order Deny,Allow
Allow from all
[+] (6) more...
comments (1) flag fork

Deny other servers from accessing your files (plain)

1
2
3
4
5
<FilesMatch "\.(gif|jpe?g)$">
    SetEnvIf Referer "^http://([^/]*\.)?domain.com/" request_ok = 1
    Order Allow, Deny
    Allow from env=request_ok
</FilesMatch>
[+] (1) more...
comments (0) flag fork

Setup alias to an alternate directory (plain)

1
2
3
4
5
6
<VirtualHost *:80>
    ServerName domain.com

    DocumentRoot /home/www/www.domain.com
    Alias /phpmyadmin "/home/www/phpmyadmin"
</VirtualHost>
[+] (2) more...
comments (0) flag fork

Allow Apache to access all projects within directory (plain)

1
2
3
4
5
6
<Directory "/path/to/projects">
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
[+] (2) more...
comments (0) flag fork

Only Allow a Specific IP Address (plain)

1
2
3
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^A\.B\.C\.D$
RewriteRule ^ https://domain.com/ [R]
comments (1) flag fork

Count Unique Visits (plain)

1
2
# Change the access.log name accordingly to match your server
awk '{ print $1 }' access.log | sort | uniq | wc -l
comments (1) flag fork

Hide Directory Structure from URL (plain)

1
2
# In httpd.conf or apache2.conf whatever the case may be...
Options -Indexes
comments (1) flag fork

Hide Apache Version Header (plain)

1
2
3
4
# In httpd.conf or apache2.conf whatever the case may be...
# Ensure the following 2 lines are set:
ServerTokens ProductOnly
ServerSignature Off
comments (0) flag fork

Redirect All Unserveable Requests to Index (plain)

1
2
3
4
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
comments (1) flag fork

Redirect to HTTPS (plain)

1
2
3
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
comments (1) flag fork