:: HOME » APACHE » htaccess configuration
 
htaccess configuration

.htaccess is used to set configuration of any specific directory. Nowadays, it mostly uses to create Search Engine Friendly pages. You can redirect any url typed with your domain to specific url. To be able to use you need modify your httpd.conf which is server configuration file and change AllowOverride to "all" and mod_rewrite  module for APACHE server. Than you can use .htaccess.

 

I will show some basic examples to help you learn how to use it.

 

RewriteEngine on

RewriteRule !\.(js|ico|gif|jpg|png|CSS)$ index.PHP

 

Over here, !(pattern) is used when url doesn’t match pattern. It means, if users type any js, ico, gif. Jpg, png or CSS file, it doesn’t apply this rule. Except these, it will apply this rule and redirect any PHP, HTML file to index.PHP file.

 

If we want to redirect just HTML files like when users types product_ABC.HTML, I want to redirect it to, product.PHP?product=ABC. So this is also search engine friendly page because search engines likes HTML pages.

 

RewriteRule product_(.*)\.htm$  product.PHP?product=$1

 

Here, at first we define url and (.*) means any thing and it will go to second page we defined. $1 first (.*) and we can use many of these like

 

RewriteRule products_(.*)_(.*)\.htm$  products.PHP?category=$1&brand=$2

 

 

If you want to redirect a directory to other;

 

RewriteCond %{HTTP_HOST} ^tr.bounmis.com$ [OR]

 

RewriteCond %{HTTP_HOST} ^www.tr.bounmis.com$

 

RewriteRule ^(.*)$ http://www.bounmis.com/tr/ [R=301,L]

 

Here, rewriteCond shows condition you can see some words at the end [OR] means its has any more condition. R=301 means it is permanent address and L means it is last rule, end of [OR] for above conditions.

 

 

If you want to redirect any url like bounmis.com/category/1/brand/5

 

RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([A-Za-z0-9-]+)/([0-9]+)/?$ products.PHP?$1=$2&$3=$4 [L]

 

These are mostly used examples .

 

At last I want to say that if your APACHE server uses CGI or fastcgi and you always get an error message like "No input file specified". Put [PT] at the end of rules

 

RewriteRule !\.(js|ico|gif|jpg|png|CSS)$ index.PHP [PT]

 


APACHE htaccess configuration APACHE htaccess configuration APACHE htaccess configuration
APACHE htaccess configuration
NEW QUESTION
 
Your E-Mail Address
»
Your e-mail will never be shown!  
   
 
Question
»
Please type your question and please use [CODE] tag for your codes!  
  Add CODE Quote BOLD ITALIC Underline Align Left Align Center Align Right Add Line  
   
 
Human Check
»
Enter human check code below!  
   
 
       
 
* Your Question will be answered as soon as possible, probably within 24 hours!
APACHE htaccess configuration APACHE htaccess configuration APACHE htaccess configuration
APACHE htaccess configuration
 
Quaware Internet Solutions And Consulting - SEO Search Engine Optimization, Website development and design, eCommerce, Online Payment Systems, Shopping Cart, Affiliates Website Designer, Search Engine Optimization Expert, Ajax Developer,Developed And Designed By Mumin Celik With Using PHP, MySQL, CSS, JavaScript, Ajax And Search Engine Optimizer Sinema, Film, Ask, Tekgul, Mutluluk