typecho开启伪静态,去掉那个讨厌的index.php
2023-06-13 09:18:41 时间
Typecho后台设置永久链接后,会在域名后加上index.php,很多人都接受不了。例如如下网址:http://zezeshe.com/index.php/archives/37/,但我们希望最终的形式是这样:http://zezeshe.com/archives/37.html。那么我们如何做到这样的效果?
1.配置服务器的rewrite规则 如果在保存上述配置的时候,typecho无法自动配置,那么你可能需要手动配置服务器的rewrite规则。
Linux Apache 环境 (.htaccess):
<IfModule mod_rewrite.c>
RewriteEngine On
# 下面是在根目录,文件夹要修改路径
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Linux Apache 环境(Nginx):
location / {
index index.html index.php;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php;
}
if (!-f $request_filename) {
rewrite (.*) /index.php;
}
}
Windows IIS 伪静态 (httpd.ini):
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# 中文tag解决
RewriteRule /tag/(.*) /index\.php\?tag=$1
# sitemapxml
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# 内容页
RewriteRule /(.*).html /index.php/$1.html [L]
# 评论
RewriteRule /(.*)/comment /index.php/$1/comment [L]
# 分类页
RewriteRule /category/(.*) /index.php/category/$1 [L]
# 分页
RewriteRule /page/(.*) /index.php/page/$1 [L]
# 搜索页
RewriteRule /search/(.*) /index.php/search/$1 [L]
# feed
RewriteRule /feed/(.*) /index.php/feed/$1 [L]
# 日期归档
RewriteRule /2(.*) /index.php/2$1 [L]
# 上传图片等
RewriteRule /action(.*) /index.php/action$1 [L]
nginx 配置
server {
listen 80;
server_name yourdomain.com;
root /home/yourdomain/www/;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
location ~ .*\.php(\/.*)*$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
access_log logs/yourdomain.log combined;
}
apache 配置
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>
2.后台配置typecho伪静态 如图,在typecho后台,开启伪静态,并选择你喜好的url形式:
请输入图片描述
具体操作,根据本人实际操作如下 我的虚拟主机是apache的,在网站根目录找到.htaccess,有的没有可能是设置了隐藏文件,显示隐藏文件就能看到了。 然后编辑.htaccess文件,加入上文中对应的apache配置代码保存。然后去typecho程序后台,设置>永久链接,按照上文中图片的设置,保存即可。
相关文章
- php最常见最经典的算法题都在这里了
- apache+php环境搭建教程_怎么搭建Php
- PHP- 特殊数据类型-resource
- PHP开启MySQL扩展的必要性(php开启mysql扩展)
- 深入PHP:实现MySQL数据库更新(php更新mysql)
- 安装Linux下的PHP环境(linux中安装php)
- PHP 存储数据到 MySQL 数据库(php写入mysql)
- Linux下快速配置PHP开发环境(linux下安装php环境)
- MySQL在PHP中的配置须知(php中的mysql配置)
- PHP与MySQL网站开发实操指南(php和mysql开发)
- 脚本Linux下使用PHP启动脚本指南(linux下php启动)
- 实现缓存PHP开启Redis超越缓存技术(php开启redis)
- PHP轻松访问MySQL数据:使用简明易懂的方法获取数据(php获取mysql数据)
- 如何使用PHP重启Linux服务:简易教程(php重启linux服务)
- mysql线程技术驱动PHP程序优化(mysql线程php)
- 如何在PHP中启用MSSQL数据库连接(php开启mssql)
- 防止MySQL注入攻击,PHP静态解决方案(mysql防注入 php)
- PHP连接MSSQL数据库:探索新的接口(php连接mssql接口)
- PHP如何开启MSSQL支持?(php怎么开启mssql)
- PHP与MSSQL的融合——开启新的编程前程(php mssql 空白)
- 用微信、PHP和MySQL构建快速、可靠的网站(微信 php mysql)
- PHP静态新闻列表自动生成代码
- 20个非常有用的PHP类库加速php开发
- php获取全局变量的代码
- PHP和Mysqlweb应用开发核心技术第1部分Php基础-1开始了解php
- 浏览器关闭后,能继续执行的php函数(ignore_user_abort)
- 基于PHP静态类的原罪详解
- php生成excel列序号代码实例