Is there a better way than this???
Moderator: General Moderators
Is there a better way than this???
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???
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.
-
x_mutatis_mutandis_x
- Forum Contributor
- Posts: 160
- Joined: Tue Apr 17, 2012 12:57 pm
Re: Is there a better way than this???
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.
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???
"a-zA-Z0-9_-" can be replaced with "\w-"
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Is there a better way than this???
thanks for the replies..
can anyone suggest some links or pdf to understand more on front controller pattern for url rewriting?
can anyone suggest some links or pdf to understand more on front controller pattern for url rewriting?