Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Remigijus Jarmalavičius ReekenX

🏠
Working from home
Block or report user

Report or block ReekenX

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ReekenX
ReekenX / prestashop_fix_for_apache
Created May 9, 2014
Prestashop 1.6 fix for Apache 2.4 (only for dev mode!)
View prestashop_fix_for_apache
find -iname '.htaccess' -exec sed 's/Deny from all//' -i {} \;
@ReekenX
ReekenX / .htaccess
Created Mar 19, 2014
Universal redirect to www
View .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
@ReekenX
ReekenX / .htaccess
Created Mar 19, 2014
Redirect to maintenance except custom IP's
View .htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteRule $ /maintenance.html [R=302,L]
@ReekenX
ReekenX / .htaccess
Created Mar 19, 2014
Prevent hotlinking
View .htaccess
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 Mar 19, 2014
Deny access to some files
View .htaccess
<FilesMatch "(install\.sql|config\.php|config\.php\.sample)$">
deny from all
</FilesMatch>
@ReekenX
ReekenX / .htaccess
Created Mar 19, 2014
Custom Error pages
View .htaccess
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 Mar 19, 2014
Cache file extensions
View .htaccess
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 Mar 19, 2014
Limit single IP
View .htaccess
<Limit GET POST>
order allow,deny
deny from 200.49.176.139
allow from all
</Limit>
View words_limit.php
<?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 );
}
View validate_url.php
<?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.";
}
You can’t perform that action at this time.