Static url. Can I use regular expressions to obtain URL parameters for routing or rewrite htacess? How do you do this? please give me some advice.
Cainiao believes
The only disadvantage of htacess is that the server environment does not support htacess, so it is difficult to win the system.
What about regular expression retrieval? it is troublesome to call
For example, a url http://xxx.com/music /pop songs /chinese /22.html
This structure looks beautiful. In fact, I only need to query the database with the last parameter '22' and the last two 'China'. the parent directory can be crawled through the parent value.
If the directory depth is not fixed
How do I obtain the last parameter and the second to the last?
$ Url = array_slice (explode ('/', $ _ SERVER ['request _ URI ']), 0 );
Reply to discussion (solution)
$ Url = "http://xxx.com/music /popular songs /chinese /22.html"; $ pathinfo = pathinfo ($ url); var_dump ($ pathinfo ['filename']); // 22 $ dir = pathinfo ($ pathinfo ['dirname']); var_dump ($ dir ['filename']); // Chinese
When urlrewite is not available, your/music/popular songs/Chinese/22.html is obviously 404
So you only use your 404 handler to process
However, this involves web server settings, and the circle is bypassed.
For
How do I obtain the last parameter and the second to the last?
$ Url = array_slice (explode ('/', $ _ SERVER ['request _ URI ']), 0 );
No. you have not figured out the parameter usage.
$ Url = array_slice (explode ('/', $ _ SERVER ['request _ URI ']),-2 );
You can.
Use regular expressions to control pseudo-static data, which is easier to configure and suitable for code segments.
The. htaccess server must support rewrite and. htaccess file parsing.
$ Url = array_slice (explode ('/', $ _ SERVER ['request _ URI ']),-2 );
It can also be a negative number. thank you for learning.