URL Rewrite - remove directory name in the URL - PHP

て烟熏妆下的殇ゞ 提交于 2019-12-13 16:57:28

问题


I want to rewrite the url like this:

http://localhost/public/viewbusiness.php?s=cyberbooger-web-services

into

http://localhost/viewbusiness.php?s=cyberbooger-web-services

thus removing the directory name in the url. You noticed that the viewBusiness.php is located in the public directory.

My application is not following the MVC architecture, and not using a framework. This is a application I am doing right as I currently studying PHP.

My folder structure is like this:

-- /app

-- /public

-- index.php

Can anyone help me? Thank you so much!


回答1:


Try:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\w+)/(\w+)$ $1/public/$2 [QSA]
</IfModule>


来源:https://stackoverflow.com/questions/8557181/url-rewrite-remove-directory-name-in-the-url-php

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