简体   繁体   English

如何在PHP中隐藏index?q =?

[英]How to hide index?q= in php?

See, I am developing my application on core php and with that I am working on an application in which the index.php file loads all the template files according to the query. 看,我正在核心php上开发我的应用程序,并且正在使用其中index.php文件根据查询加载所有模板文件的应用程序。 eg; 例如; if user want to go to profile page, the url is, sitename/index.php?q=profile , and for settings page the url is, sitename/index.php?q=settings . 如果用户要转到个人资料页面,则URL为sitename/index.php?q=profile ;对于设置页面,该URL为sitename/index.php?q=settings

I want to make it clean url, like for profile the url should be like, sitename/profile and sitename/settings . 我想将其设为干净的url,例如对于个人资料,该网址应类似于sitename/profilesitename/settings

I have searched alot on this topic but has not been successful. 我已经在这个主题上进行了大量搜索,但没有成功。 Any help would be appreciated. 任何帮助,将不胜感激。 Thankyou. 谢谢。

you could use following code in your .htaccess file to have clean url 您可以在.htaccess文件中使用以下代码来获取干净的网址

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?q=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1

请学习如何在.htacces中定义规则。您可以从这里开始,也可以在stackoverflow答案中查看示例。

Either shift to MVC architecture and define your routes there accordingly, or use asynchronous requests through JavaScript and fetch and render stuff on the front end itself. 要么转换为MVC架构并在那里定义路由,要么通过JavaScript使用异步请求,并在前端本身获取和呈现内容。 Given your situation, both options would take about the same time to implement. 根据您的情况,两种选择都将花费大约相同的时间来实施。 Consider other factors of your project and then chose wisely. 考虑项目的其他因素,然后明智地选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM