Link to home
Start Free TrialLog in
Avatar of Robert Saylor
Robert SaylorFlag for United States of America

asked on

.htaccess

My .htaccess is kinda like a route if you compare it to Laravel. I want to optimize this but not sure how.

Here is what I am doing:

RewriteRule ^dashboard/?$ index.php?section=dashboard [NC,L]
RewriteRule ^edituser/([a-zA-Z0-9]+)/?$ index.php?section=edituser&id=$1 [NC,L]
RewriteRule ^editroom/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ index.php?section=editroom&id=$1&id2=$2 [NC,L]

Open in new window


So I am passing 1, 2 or possible 3 params on the URL. Anyway to make this less code and possible a catch all deal?

My URL would look like:

http://localhost/parm1/parm2/parm3 but not all have 2 or 3 parms

http://localhost/parm1
http://localhost/parm1/parm2
http://localhost/parm1/parm2/parm3

etc...
Avatar of Systech Admin
Systech Admin
Flag of India image

What you are actually want to achieve with this? Could you please explain more
I think you're on the ball when you say "is like a router".  That's exactly what you're trying to do.  By the same token, a router is much easier to implement in your code than it is in mod_rewrite.  I recommend moving this from your htaccess to a true routing component in your application.
Avatar of Robert Saylor

ASKER

Thanks Steve,

I am mainly using htaccess to get the nice SEO affect. I already have my code routing nicely and uses a DB to figure out where goes where and who has access. I could do this without htaccess but then I loose the SEO affect. My htaccess file is getting long and was wondering if it can be somewhat automatic but if not I don't mind adding lines to it.
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks I will give this a test shortly
I started thinking and the ones that has a 2nd or 3rd param the name I pass to my PHP are different but the 1st one is the most common my script will use so by using your example I was able to remove 29 rules and future one line rules I won't have to insert. Thanks!!!

RewriteRule ^/?([^/]*)$ index.php?section=$1 [NC,L]