I have no issues with setting up the mod_rewrite and having it create the clean URLs. My question is for more experienced htaccess users and I am wondering if there is a simple solution to my dilemma.
My URLs without the cleanup look like:
index.php?ctrl=portal&mode=main
or
index.php?ctrl=portal&mode=edit&id=2
I want my URLs to look like:
http://www.mydoamin.com/portal/main
or
http://www.mydoamin.com/portal/edit/2
I can easily have the clean URL with the ctrl/mode; my issue is, how can I setup the rewrite so that if the id (id is only an example, this var could be anything) will only append to the URL if it is set?
currently I am using
# Turn on RewriteEngine
RewriteEngine on
RewriteBase /
# Do a www redirect on the domain
RewriteCond %{HTTP_HOST} ^test\.dev [NC]
RewriteRule ^(.*)$ http://www.test.dev/$1 [R=301,L]
# Make sure it's not a file or a folder before we attempt a redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Perform main redirect
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index\.php?ctrl=$1&mode=$2 [L]
# If loading just the index, redirect to /
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html)\ HTTP
RewriteRule ^(.*)index\.(php|html)$ /$1 [R=301,L]
The ctrl and mode will always be in the URL, sometimes there will be more vars passed. I would like each of these vars to be appended to the URL via "/". IE: /portal/main or /portal/edit/2 or /user/manage/2/contacts. I hope this is explained with enough detail.
Does anyone know any good methods to achieve this functionality? I am not an expert in htaccess but I am no beginner either. Any other ideas or suggestions would be much appreciated.
Thanks