Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP all GET parameters with mod_rewrite



I am designing my application. And I should make the next things. All GET parameters (?var=value) with help of mod_rewrite should be transform to the /var/value. How can I do this? I have only 1 .php file (index.php), because I am usign the FrontController pattern. Can you help me with this mod_rewrite rules?

Sorry for my english. Thank you in advance.

like image 503
Alex Pliutau Avatar asked Dec 04 '22 23:12

Alex Pliutau


1 Answers

I do something like this on sites that use 'seo-friendly' URLs.

In .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]

Then on index.php:

if ($_SERVER['REQUEST_URI']=="/home") {
    include ("home.php");
}

The .htaccess rule tells it to load index.php if the file or directory asked for was not found. Then you just parse the request URI to decide what index.php should do.

like image 105
profitphp Avatar answered Dec 10 '22 11:12

profitphp