将url重写为site.php作为站点

时间:2015-02-22 09:29:47

标签: php .htaccess mod-rewrite rewrite

这是我的文件

index.php
blog.php
about.php

我正在访问它

localhost/index.php or localhost
localhost/blog.php
localhost/about.php

如何重写.htaccess以便我可以通过

访问它
localhost/
localhost/blog
localhost/about

更新

我应用以下提供的.htaccess时,我的图片没有显示,是否可以解决此问题?

3 个答案:

答案 0 :(得分:0)

Options -MultiViews # optional Depends on Server
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

修改

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

答案 1 :(得分:0)

.htaccess文件中进行简单尝试:

RewriteRule ^([a-zA-Z0-9_-]+)$ $1.html

答案 2 :(得分:0)

在.htaccess文件中

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php