Monday, 19 August 2013

htaccess simplified and remove need for trailing a slash

htaccess simplified and remove need for trailing a slash

I am writing my very first htaccess and would like help cleaning it up and
understanding it. The first issue I am having is with mulitple parameters.
my current setup looks like:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|ico|img|js)/
RewriteRule ^([^/]*)/([^/]*)$ index.php?p1=$1 [L]
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|ico|img|js)/
RewriteRule ^([^/]*)/([^/]*)$ index.php?p1=$1&p2=$2 [L]
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|ico|img|js)/
RewriteRule ^([^/]*)/([^/]*)$ index.php?p1=$1&p2=$2&p3=$3 [L]
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|ico|img|js)/
RewriteRule ^([^/]*)/([^/]*)$ index.php?p1=$1&p2=$2&p3=$3&p4=$4 [L]
Is there a way to simplify this to handle up to a maximum of 4 parameters
with all of them being optional? Which leads me to me next problem that it
seems that if you need to have a trailing slash after the parameters
unless you are using all 4 parameters.
In short I would like my urls to look like this...
http://www.example.com/home
http://www.example.com/home/
http://www.example.com/blog/i-am-a-title
http://www.example.com/blog/i-am-a-title/
http://www.example.com/varable1/varable2/varable3/varable4
http://www.example.com/varable1/varable2/varable3/varable4/
I'll appreciate any help that you can provide.

No comments:

Post a Comment