home

Quickies, by Andrea Olivato

text

Htaccess rewrite : forward query string and add params

This shows a simple solution to make some redirs adding parameters to querystring. I used this to implement an API service.

Options +FollowSymlinks
RewriteEngine on
 
RewriteCond %{REQUEST_URI} !/index.php* [NC]
RewriteCond %{QUERY_STRING} ^(.+)$ 
RewriteRule ^([^.]+).([^?]+)$ index.php?method=$1&format=$2&%1

Example request:

/create.json?param=something&foo=smelse

Redirects to

/index.php?method=create&format=json&param=something&foo=smelse

2 years ago

July 29, 2009
Comments (View)
text

Htaccess redirects non-static non-existing files to index.php

This is the fastest way to achieve a good url rewriting in Php, redirecting every non-existing file or directory to the index.php. The following htaccess also make chekcs to exclude automatically images,js,css from being redirected

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !^.*\.png [nc]
RewriteCond %{REQUEST_FILENAME} !^.*\.css [nc]
RewriteCond %{REQUEST_FILENAME} !^.*\.jpg [nc]
RewriteCond %{REQUEST_FILENAME} !^.*\.js [nc]
RewriteCond %{REQUEST_FILENAME} !^.*\.gif [nc]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

3 years ago

May 16, 2009
Comments (View)