Skip to content

Instantly share code, notes, and snippets.

View ReekenX's full-sized avatar
💻
React, Vue, Rails, Python

Remis Jarmalavicius ReekenX

💻
React, Vue, Rails, Python
View GitHub Profile
@ReekenX
ReekenX / prestashop_fix_for_apache
Created May 9, 2014 03:43
Prestashop 1.6 fix for Apache 2.4 (only for dev mode!)
find -iname '.htaccess' -exec sed 's/Deny from all//' -i {} \;
@ReekenX
ReekenX / .htaccess
Created March 19, 2014 05:09
Universal redirect to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
@ReekenX
ReekenX / .htaccess
Created March 19, 2014 05:09
Redirect to maintenance except custom IP's
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteRule $ /maintenance.html [R=302,L]
@ReekenX
ReekenX / .htaccess
Created March 19, 2014 05:08
Prevent hotlinking
RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
@ReekenX
ReekenX / .htaccess
Created March 19, 2014 05:08
Deny access to some files
<FilesMatch "(install\.sql|config\.php|config\.php\.sample)$">
deny from all
</FilesMatch>
@ReekenX
ReekenX / .htaccess
Created March 19, 2014 05:07
Custom Error pages
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html
@ReekenX
ReekenX / .htaccess
Created March 19, 2014 05:07
Cache file extensions
FileETag MTime Size
<ifmodule mod_expires.c>
<filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresActive on
ExpiresDefault "access plus 1 year"
</filesmatch>
</ifmodule>
@ReekenX
ReekenX / .htaccess
Created March 19, 2014 05:06
Limit single IP
<Limit GET POST>
order allow,deny
deny from 200.49.176.139
allow from all
</Limit>
@ReekenX
ReekenX / words_limit.php
Created March 19, 2014 05:03
Words limit
<?php
function words_limit( $str, $num, $append_str='' ){
$words = preg_split( '/[\s]+/', $str, -1, PREG_SPLIT_OFFSET_CAPTURE );
if( isset($words[$num][1]) ){
$str = substr( $str, 0, $words[$num][1] ).$append_str;
}
unset( $words, $num );
return trim( $str );
}
@ReekenX
ReekenX / validate_url.php
Created March 19, 2014 05:02
Validate URL
<?php
$url = "http://example.org/";
if (preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $url)) {
echo "Your url is ok.";
} else {
echo "Wrong url.";
}