怎么到PHP页面,而无需使用的.php的网址页面、网址、PHP、php

2023-09-02 00:38:37 作者:余罪°

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

I have a static website with files like index.php, blog.php, contact.php etc

我怎样才能让我的网站地址,工作,让www.site.com/blog把你带到blog.php的?

How can I get my website addresses to work so that www.site.com/blog takes you to blog.php?

我觉得htaccess的可以帮我这个忙,但我一个PHP小白!

I think htaccess could do this for me, but am a php noob!

我目前使用的唯一的选择是创建一个名为个人文件夹博客,请等等,这里面包含它的另一个index.php文件

The only alternative I currently use is to create individual folders called 'blog, contact etc' which contains another index.php file inside it

感谢

推荐答案

是的,你可以使用mod_rewrite重写所有URL。下面将改写所有不存在的文件和文件夹,文件名请求的.php:

Yes, you can use mod_rewrite to rewrite all urls. The following will rewrite all non-existing files and folders to requested filename .php:

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

访问 /博客,它不是现有的目录将导致此规则重写为 /blog.php

Visiting /blog and it's not an existing directory will cause this rule to rewrite it as /blog.php.