如何在不使用URL中的.php的情况下访问php页面

fal*_*ter 2 html php url .htaccess

我有一个静态网站,其中包含index.php,blog.php,contact.php等文件

如何让我的网站地址工作,以便www.site.com/blog将您带到blog.php?

我认为htaccess可以为我做这个,但我是一个PHP菜鸟!

我目前使用的唯一选择是创建名为"blog,contact etc"的单个文件夹,其中包含另一个index.php文件

谢谢

ale*_*exn 9

是的,您可以使用mod_rewrite重写所有网址.以下内容将所有不存在的文件和文件夹重写为请求的文件名.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
Run Code Online (Sandbox Code Playgroud)

访问/blog并且它不是现有目录将导致此规则将其重写为/blog.php.