Currently my .htaccess code sends the {REQUEST_URI}
as a $_GET
array to load.php
where that page calls up the controllers for the request. For SEO purposes, I would like to remove a portion of the URL without changing the $_GET
array that is sent to load.php
.
For example if I have:
domain.com/products/product-name
I would like the URL to display:
domain.com/product-name
without changing the $_GET
variable that is sent to load.php
.
Any help would be greatly appreciated. I've included my current code.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
CLARIFICATION:
$_GET[0]
serves as a 'controller' variable which directs the application to open up the appropriate file. Therefore, I can't hardcode 'products' into $_GET[0]
because that would constantly open up controllers/products.php
instead of the appropriate file.
I would like the URL to display:
domain.com/product-name
without changing the $_GET variable that is sent to load.php.
The only way to do what you're asking is to hardcode part of the URL in the substitution string of the rewriterule with products
. See below. Then URL load.php will always receive products/somefile
.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=products/$1 [L,QSA]
Update: This solution will work if you have one path/controller you want to substitute.
You have to reference the controller some how. So if you don't have the controller in the request there is nothing to forward to the $_GET variable. PHP will not know where the request is supposed to go. There is nothing wrong with having that in the path and it should not affect your SEO.