How to execute a PHP web page without the .php extension in the URL?

后端 未结 6 634
野趣味
野趣味 2021-02-01 06:24

Sorry for noob question, can\'t understand from what I should search.

I\'m making a site with that page product.php?id=777
I\'d like it to be pro

6条回答
  •  梦如初夏
    2021-02-01 06:55

    This is something that frameworks like CodeIgniter and Zend accomplish with ease, but can still be accomplished with just Apache's mod_rewrite, as others have suggested. Basically, use a .htaccess like this to direct all traffic to a one page:

    
        RewriteEngine On
    
            RewriteCond                     %{REQUEST_FILENAME} !-f
            RewriteCond                     %{REQUEST_FILENAME} !-d
        RewriteRule                 ^(.*)$ index.php?_url=$1 [QSA,L]
    
    

    Once you get on that page you can parse that _url variable, which can be whatever format you want, and handle the request appropriately.

提交回复
热议问题