Create a page without placing .php at the end?

北慕城南 提交于 2019-12-24 00:19:20

问题


I was looking for ways to mimic something I've seen, however I'm really not even sure where to start or how to search for it.

Lets say my page was:

foo.com/ and my index page could take an argument of: index.php?id=5

What I'm wanting to do is create the following:

foo.com/5/ rather than placing index.php?id=5 just use the webstring to pass in the parameters, to hide not only the fact its a PHP page, but to clean up the url a bit more.

Is this possible?

Cheers


回答1:


You'll want to look into URL rewriting. With the commonly used Apache webserver, this is accomplished with mod_rewrite.




回答2:


or /?5/123/ and in php parse the query string if rewrite is not available




回答3:


Something like this should suit:

RewriteRule ^pages/([A-Za-z_-]*)(/?)$ /index.php?page=$1

Broken down, we're looking for a URL that starts with pages, has any combination of letters, underscores and hyphens, and an optional trailing forward slash, and passing that to /index.php to handle.




回答4:


Yes Mod_rewrite is best option, you can create .htaccess file. if you do not want the write a custom function which will handle the your url.



来源:https://stackoverflow.com/questions/1455071/create-a-page-without-placing-php-at-the-end

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!