Search code examples
.htaccessurlhttp-redirectsef

Send all incoming URL request's through 1 file, getting Path Parameters for PHP


I want the majority of the incoming URL requests to point to a global processorfile

**www.itsme.com/index.php**

The URL's can have all sort of structures but always with '/' instead of '?|&|=', eg

  • www.itsme.com/news/finance/
  • www.itsme.com/news/money/trading
  • www.itsme.com/sports

The index.php should be able to recognize the URL and its parameters it has been called from, eg

array{[1]=>news,[2]=>finance})

Since i have many directories i want to better avoid placing in every one a (.htaccess) file seperately to do the redirect.

Apache / Linux / PHP 5.3

How could this be done?thx


Solution

  • So easy it was. Placing this 1-liner in root as .htaccess will do:

    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?var1=$1&var2=$2&var3=$3&var4=$4 [NC]
    

    isn't it great?