删除的.html和.PHP与htaccess的扩展 [英] Remove .html and .php extensions with .htaccess

查看:326
本文介绍了删除的.html和.PHP与htaccess的扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何删除我的网页文件类型,而无需创建一个新的目录和命名index.php文件。我想 http://example.com/google.html 到的 http://example.com/google

How do I remove the file type from my webpages without creating a new directory and naming the file index.php. I want http://example.com/google.html to http://example.com/google.

我怎么会去这样做。

PS:我试图寻找一些其他的教程,但那里混乱。我现在做的,它可以在.htaccess做

PS: I tried looking at some other tutorials but there to confusing. I do now that it can be done in .htaccess

推荐答案

是的,我知道这个问题是问多遍了,并回答了,但我会根据我的经验给多一点COM prehensive答案

Yes, I know that this question was asked multiple times already and is answered, but I will give a little more comprehensive answer based on my experience.

下面是的.htaccess code段,将帮助你:

Here is the .htaccess code snippet that will help you:

# Apache Rewrite Rules
 <IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /

# Add trailing slash to url
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
  RewriteRule ^(.*)$ $1/ [R=301,L]

# Remove .php-extension from url
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^([^\.]+)/$ $1.php 

# End of Apache Rewrite Rules
 </IfModule>

我要强调一些重要的东西在这里供大家参考:

I want to stress some important things here for everybody's reference:

  • 这code段不会从URL中删除条目脚本(如 的index.php 被许多PHP框架)
  • 它只是删除的.php 扩展,如果你想删除其它分机以及(如的.html ),复制并粘贴3号地块和替换 PHP 与其他扩展。
  • 不要忘了还可以删除扩展名由锚(链接)HREF。
  • This code snippet doesn't remove entry scripts from url (such as index.php used by many PHP frameworks)
  • It only removes .php extension, if you want to remove other extension as well (e.g. .html), copy and paste 3rd block and replace php with other extension.
  • Don't forget to also remove extension from anchors (links) href.

这篇关于删除的.html和.PHP与htaccess的扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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