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.