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

后端 未结 6 641
野趣味
野趣味 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 07:16

    For me this code work:

    in "/etc/apache2/sites-available/default" or "httpd.conf"

    you must have (at least) these options in the default directory

    ...
        
            ...
            Options FollowSymLinks
            AllowOverride All
            ...
        
    ...
    

    OR in the site specific site directory

    ...
        
            ...
            Options FollowSymLinks
            AllowOverride All
            ...
        
    ...
    

    and create (it may not exist, make sure it is readable by apache) or edit the ".htaccess" in the directory of the site (for example "/var/www/my-site/.htaccess") and add this code:

    AddType application/x-httpd-php htm html php
    AddHandler application/x-httpd-php .htm .html
    
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    

提交回复
热议问题