I'm building a simple MVC structure, my intention is to also have simple URLs (without the file and .php extension), basic rules:
Here is how I'm hiding index.php from my URLs on the htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
This allows me to do /1/2
To determine my URL in PHP, I do:
$url_parts = array_filter(explode("/", $_SERVER["REQUEST_URI"]));
This gives me access to all ny URL segments, I load different files depending on $url_parts[0] (controller) and $url_parts[1] (method/function)
I only have one concern now, and that is working with $_GET on my pages, if I access something like:
/1/2?foo=bar
My $_GET returns:
Array ( [/1/2] => )
Whereas I'd obviously want it to be:
Array ( [foo] => bar )
Can my code be salvaged at all? I obviously don't know how $_GET works that well, I was expecting this to work OK.
Look at the QSA (Query String Append) flag, e.g.
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With