How to do URL re-writing in PHP?

前端 未结 9 2080
死守一世寂寞
死守一世寂寞 2020-11-22 14:38

I am trying to implement URL rewriting in my PHP application. Can someone share a step by step procedure of implementing URL rewriting in PHP and MySQL?

In my applic

9条回答
  •  遇见更好的自我
    2020-11-22 15:15

    Unfortunately, it's really up to the web server, not PHP. Depending on if you use Apache or something else, it has to do this before your script is executed. I use mod_rewrite, and an example rewrite rule looks like this:

    
        RewriteEngine On
        RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/%{REQUEST_URI} [PT,L]
    
    

    The above rule basically says if the URL is a valid path to a real file or directory, load it. Otherwise, run it through index.php.

提交回复
热议问题