OldCat's Diary

oldcat

利用.htaccess去掉TYPECHO链接中的index.php

June 4th, 2015 9:16 PMNo CommentsFiled under: 网站技术Feed for this Entry

TYPECHO博客程序是支持伪静态的,但我的一个英国主机安装好程序后在地址链接中总是带着index.php,例如:http://www.mydomain.top/index.php/tech/16.html/
这个可能是主机的问题,虽然说不耽误使用但看着的确有些不舒服,百度了一下,解决方法是有的,可我一用就是404,最后用了.htaccess终于是把这index.php去掉了。
在一般的.htaccess中打开伪静态是:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
那么只要把最后的
RewriteRule ^(.*)$ /index.php/$1 [L]
替换为:
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
就可以了。

我的完整的.htaccess就是:

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

RewriteCond %{HTTP_HOST} ^mydomain.top
RewriteRule (.*) http://www.mydomain.top/$1 [R=301,L]

后面两句是根域名跳转至WWW二级域名,可以无视。

把.htaccess文件编辑好后上传到空间根目录,然后进博客后台把永久链接启用,设置好自定义文章形式,保存,这时会有红字提示:
重写功能检测失败, 请检查你的服务器设置
如果你仍然想启用此功能, 请点击这里
最后点击就OK了。

转自:http://www.balinglife.com/754.html

TAGS: Null

Leave a Comment: