URL Rewrite - remove directory name in the URL - P

2019-07-15 12:51发布

问题:

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>