I'm currently using Apache 2.2
I can do simple things like
RewriteRule ^/news$ /page/news.php [L]
RewriteRule ^/news/(.*)$ /page/news.php?id=$1 [L]
but what if I want to send 2 parameters like this
http://www.example.com/link/param1/param1_value/param2/param2_value
Lastly, I want to also know implementing SEO friendly URL like stackoverflow
though I can get access to a page with URL like
Just decorating that URL with
Give me some suggestion with example snippets.
Note Google have stated that they prefer
news.php?id=$1
instead ofnews/$1
because it is easier for them to detect the variable. This is more pertinent when increasing the number of variables as just looking at your first example is a bit confusing:You can always combine the two if one parameter is generic like a category:
One should really reevaluate the design if more than one parameter is required and it is not a temporary search.
I know that the PHP symfony framework allows you to do that.
How does it work : In apache config, use mod_rewrite to redirect ALL incoming resquest to a single entry point (in symfony this is called the "front controller")
In this front controller you are going to create a "Request" object which holds all the informations provided by the URL.
For example you could say that the first thing after the "/" is the name of the PHP file to call and everything else are parameters and values so that : http://example.com/file/id/2 will call file.php with id=2
To do that, just use some reg exp and design you "Request" class carefully. For the example above the "Request" class should provide both getRequestedAction() and getParameter(string parameter) methods. The getRequestedAction() method will be used when the "Request" object is fully populated in order to call the correct file/action/method.
if you choose to populate the parameter array of the request object with both reg exp on the URL and a parsing of the _GET array, you may get to the point where : http://example.com/file/id/2 is the same as http://example.com/file?id=2 (and both can work)
you can choose to ignore extensions (http://example.com/file.html is the same as http://example.com/file), or not.
Finally, for some URL, you can choose to just ignore everything that goes after the last '/'. So that : http://example.com/question/3/where-is-khadafi is the same as http://example.com/question/3/is-linux-better-than-windows
In the different file.php, just use $request->getParameter('id') to get the value of the "id" parameter, instead of using the _GET or _POST arrays.
The whole point is to
Hope this helps