Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts

Sep 29, 2012

Turn off magic_quotes_gpc on shared or free hosts

magic quotes gpc

Last days i wanted to post some seo articles and this problem was a bit confusing to me.
I was searching and searching on the sources of my site and was not able to find the problem until i figured it out.
I tried .htaccess or php ini_set but had no luck.
And i came out using a php function called stripslashes.

Turn magic quotes off example



<?php
// get something
$q = $_GET['q'];
// print it out
echo stripslashes($q);
?>

It was a short tip yes, but it may help you in some situations
And dont forget to share :D

Protect server config or important files for security

server security

Securing a server is at hard task especially for beginners.
On todays topic we gonna protect server config files using htaccess.
Why we should do that ?
well if another site on same server with you gets hacked, then he can read your configuration files like config.php wp-config.php etc..
Ok lets get into point
<Files config.php>
Order allow,deny
Deny from all
</Files>

When the attacker tryes to read the config.php (as example) file it gets a 403 permission denyied.

Protecting same type files


Lets for example we wanna protect all .ini files
We can do
<Files *.ini>
Order allow,deny
Deny from all
</Files>


I just explainded what can we do to protect our config files if we dont have enough access to php.ini
If you are a server administrator you can automate this (future tutorial).

Few notes to remember


a. If you deny all .txt robots.txt will get blocked, or .xml when sitemap.xml gets blocked, but if you dont have this 2 files do whatever you want.
b. Make an separated config file, you cant protect article.php which has seme configurations(database password) since it will disallow all users to access normal files.
c. Make shure you have the right chmod (permossion) for files.
d. Dont forget to share :D :D

Mod rewrite tutorial. Creating seo frendly urls in php

mod rewrite

Hello dear readers.
In this tutorial i will explain in deepth how to make your url's beautiful and better for seo.

Benefits of mod_rewrite:

1) they are beautiful
Lets take an example:
Non rewrited url:
http://facebook.com/profile.php?id=12324231
Rewrited url:
http://facebook.com/PhpTutorials
Cool isnt it ?
2) Security
mod_rewrite is build in security
You can use some kind of filters who allow only 0-9 or a-z etc.. by not allowing dangerous charachters

Lets move on

To make mod_rewrite work we must go to apache http.conf and add this line:
LoadModule rewrite_module modules/mod_rewrite.so Then restart apache.
Now at root open or create .htaccess if you havent it
Lets for example rewrite the profile.php url:
RewriteEngine On
RewriteBase /
RewriteRule ^profile/([a-zA-Z0-9-!./]+).html$ profile.php?id=$1

Thats it, you can now integrate this rule with php scripts and here it is a tutorial

Unique Seo tips part 1 | Seo tutorial

seo tips

Today a facebook friend asked me for some unique seo tips, i said wait 15 min and ill pm you.
Well im not an seo guru but i know a bit.
This tips are not totally unique but its good to know them.

To view part 2: Unique seo tips part 2

Unique seo tips

frendly urls
There are few other tips: 
url must be lowercase only, you can do this in php:
<?php
$url = "All about SEO";
$url = strtolower($url);
?>

url must contain 4 words(best) or 5 separated with - and not _ or spaces. 
No more than 3 directories 
example:
http://localhost/article/mod-rewrite-tips.html (good ones with: - .html and less than 4 directories 
http://localhost/article/php/2012/04/post.php?id=6 (bad one with more than 4 directories and bad url type) 
http://localhost/article/mod_rewrite_tips.html (_ are not seo frendly) 
Thats all you need to know for url's

h b i tags

ok this is not unique but use them in this way:
<h1>Post title</h1> (if its an article)
if you are on pages like index.html sitemap.html about.html etc.. h1 header must be:
<h1>Site main keyword</h1> (like PHP Tutorials)
h2 must be used for second important titles
<b> and <i> (mostly <b>) must be used for main keywords like <b>seo unique tips</b> 2 or 3 times

post date is good for seo!


well when you search on google and get some crappy old content you start learning (at least i)
now when i search i use: 2011 php x x
and its not only me
if you do a google search for one of my site posts you will se date posted!
I did not included it on meta description(will be explained on part 2) but google was smart and included it :D

canonical stop dublicates


its an html tag used on head tags of the page:
<head>
<link rel="canonical" href="http://localhost/article/seo-tutorial.html">

http:// is used because my site uses http and not https or http://www
that takes to serious dublicate content
Make sure you use only one of those protocols.
This .htaccess rule redirect users who dont use your protocol:
Note: you must enable mod_rewrite.

# seo rule
# redirects http:// to http://www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost[NC]
RewriteRule ^(.*)$ http://www.localhost/ $1 [L,R=301]


Redirect www to non www:
RewriteCond %{HTTP_HOST} ^ www.localhost [NC]
RewriteRule ^(.*)$ http://localhost/ $1 [L,R=301]

Aug 12, 2012

Unique Seo tips part 2 | Seo tutorial

seo tips

Note! It is highly recommended to read the first part of unique seo tips

This is second part of unique seo tips
Today i will be explaining meta keywords ,description and title 
Well a bit advanced..

Meta Keywords
an example would be:

<head>
<meta name="keywords" content="php tutorials, web security, seo lessons">
</head>

I used some random keywords.
Do not focus on meta-keywords!!
Wordpress plugin "yoast" has not included them by default. 
The reason is that google started not using them at 2009, then yahoo. 
So is no meaning at all since even blogger does not include them hehe. 
But most of us just keep adding them. 
In my opinion if you do not put them for X article just put site main keyword at each page :) 
Peoples try to have a limit of 200 charachters on keywords(its just preference) 

Meta description
An live example would be:
<meta name="description" content="Php tutorials provides unique Php and Jquery tips. Lot of scripts and downloads">
</head>

Meta description must be: 
Unique 
Well explained 
Up to 3 inportant keywords inside 
Limited 150 to 160 charachters 

It appears on google search results so be user frendly :)

Title tag
It's not an unique seo tip at all but its a must know 

Title example:


<head>
<title>Php tutorials | Dialy php and jquery examples</title>
</head>
Title rules: 
up to 65 charachters 
well explained + words 

A fast tip! If title is to short add and your site at end like: 
title | Php Tutorials 

On third part we will speak about "Being frendly with google". 

Dont forget to share :) :)

Jun 8, 2012

Protecting files same as htpasswd but using php (new tip)

Hello all
This is a quick and cool php tip im gonna show you.
We will make an login page just like htpasswd but using php.

Why is this good?!
Well often hackers when hacking a server try to read .htpasswd files but without knowing that isn't there will make them search for a while, or even not find it :)

Live preview:


Open a php file you want to protect or just create a new one xD

<?php

$config['admin_username'] = "username"; // your username
$config['admin_passowrd'] = "password"; // your password
if(!isset($_SERVER['PHP_AUTH_USER'])){
header("WWW-Authenticate: Basic realm=\"Login\"");
header("HTTP/1.0 401 Unathorized");
die("No login passed lol");
}
else{
if(!($_SERVER['PHP_AUTH_USER'] == $config['admin_username'] && $_SERVER['PHP_AUTH_PW'] == $config['admin_passowrd'])){
header("WWW-Authenticate: Basic realm=\"Login\"");
header("HTTP/1.0 401 Unathorized");
die("What happens when you press cancel :P ");
}
}
?>

Thats it, dont forget to share xD

Jun 6, 2012

Prevent directory browsing using htaccess - Security tip!

prevent directory browsing

If you visit a website like site.com/folder1/ it will display all its contents.
What if you had an inportant file in there, everyona can se it.
Dont worry, apache did for us!
Using a simple htaccess rule we can easily disable this option.

# this is a comment
#this is the rule we must add
Options -indexes

Alright, when someone tryes to access that folder it will get an 403 Forbitten and not be able to watch the file.
An other way is to add at every folder and index.html but the first one is more fast :)