Page 1 of 1
Is there a better way than this???
Posted: Wed May 09, 2012 5:53 am
by azycraze
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?module=$1&link=$2&control=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\=([a-zA-Z0-9_-]+)$ index.php?module=$1&link=$2&$3=$4
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?module=$1&link=$2
RewriteRule ^([A-Za-z0-9\_\-\/]+)/$ index.php?module=$1
is there any way to simplify this url rewriting???
pls help!!!
Re: Is there a better way than this???
Posted: Wed May 09, 2012 6:15 am
by Celauran
Use a front controller. Redirect all requests to the front controller and let PHP sort out the rest. Much easier than trying to do it all through .htaccess.
Re: Is there a better way than this???
Posted: Wed May 09, 2012 9:57 am
by x_mutatis_mutandis_x
Rewriting URLs in apache config for php scripts, is like <url-pattern></url-pattern> in web.xml for servlets. As long as you have a generic pattern matching with wild-characters, it would make more sense in using them. But for simple action routing, using front-controller pattern is better (like Celauren suggested) as you have a control over the routing scheme, and you can customize it to your needs.
Also avoid using .htaccess (esp. in production) as it's read on each time the directory under which it's located, is accessed by apache. If you have a virtual-host or default configuration, better to specify your rewrite rules in <Directory></Directory>. These files are read once when apache server starts/re-starts.
Re: Is there a better way than this???
Posted: Wed May 09, 2012 12:02 pm
by pickle
"a-zA-Z0-9_-" can be replaced with "\w-"
Re: Is there a better way than this???
Posted: Thu May 10, 2012 12:10 am
by azycraze
thanks for the replies..
can anyone suggest some links or pdf to understand more on front controller pattern for url rewriting?