怎么到PHP页面,而无需使用的.php的网址 [英] How to get to php pages without using .php in URL

查看:148
本文介绍了怎么到PHP页面,而无需使用的.php的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静态的网站中包含的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.

这篇关于怎么到PHP页面,而无需使用的.php的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆