Static url. Can I use regular expressions to obtain URL parameters for routing or rewrite htacess?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.