Static URLs, getting URL parameters with regular routing good or htacess rewrite good

Source: Internet
Author: User
Static URL, use regular to get URL parameter to route good or htacess rewrite good?
Daniel, what do you do?

Rookie thinks

Htacess The only downside is that the server environment does not support Htacess is dumbfounded win system more trouble

Regular fetch, the time to call is more troublesome

Like a URL http://xxx.com/music/pop/Chinese/22.html

This structure looks more beautiful actually I just need the last parameter ' 22 ' and the penultimate ' Chinese ' to query the database, the parent directory can be climbed up through the parent value.

If the directory depth is not fixed
How do I get the last parameter and the penultimate one?
$url = Array_slice (Explode ('/', $_server[' Request_uri ']), 0);




------Solution--------------------
$url = "http://xxx.com/music/pop song/Chinese/22.html";
$pathinfo = PathInfo ($url);
Var_dump ($pathinfo [' filename ']);//22
$dir = PathInfo ($pathinfo [' dirname ']);
Var_dump ($dir [' filename ']);//Chinese

------Solution--------------------
When there is no urlrewite, your/music/pop/Chinese/22.html is obviously 404
So you're only dealing with your own 404-handler.
But this involves setting up the Web server again, and the circle is going around again.

For
How do I get the last parameter and the penultimate one?
$url = Array_slice (Explode ('/', $_server[' Request_uri ']), 0);
No, you didn't figure out the use of parameters.
$url = Array_slice (Explode ('/', $_server[' Request_uri ']),-2);
You can do it.

------Solution--------------------
Through regular control pseudo-static, this is relatively easy to configure, suitable for code snippets.
The. htaccess server must support rewrite and. htaccess file parsing is valid.
  • 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.