简体   繁体   中英

URL Rewrite - remove directory name in the URL - PHP

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!

Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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