Typecho默认的文章地址带有index.php,怎么去掉

/ 0评 / 0

Typecho 默认的地址带有index.php这个文件,我很不喜欢。Typecho如何去除URL链接中的index.php?

在默认情况下,Typecho能够正常工作后,所有文章的URL都会是类似

https://evvcv.com/index.php/archives/sample.html

这里的index.php对于强迫症患者影响还是挺大的,其实这里只需要进入Typecho后台控制面板。

1,点击设置->永久链接

2,将“是否使用地址重写功能”改为启用,这里可能系统提示不支持地址重写,选择强制开启之类的就行了。
3,再在“自定义文章路径”中选择自己喜欢的URL格式,保存设置后马上就生效了。

如果启用地址重写后打不开文章链接,如果你用的是宝塔搭建的网站,可以到宝塔面板添加伪静态设置,选择typecho即可 如下图:

这样就可以打开去除index.php的链接了,而原来带有index.php还可以正常打开。


第二种方法:如果你不是宝塔搭建的网站,那就需要更改伪静态:

配置服务器的 rewrite 伪静态规则

Nginx

主要关注nginx配置文件,例如:nginx.conf

server {
        listen          80;
        server_name     richerdyoung.com;
        root            /home/laofan/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/richerdyoung.com.log combined;
    }

Apache

主要是修改 .htaccess 文件。

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

第三种方法:可以通过Typecho后台设置伪静态:

在 typecho 后台,开启伪静态,并选择你喜好的 url形式:

网站设置-》永久链接,选择启用地址重写功能。

例如:

  1. 登录管理界面
  2. 设置
  3. 永久链接
  4. 启用地址重写功能
  5. 勾选仍然启动此功能
  6. 选择wordpress风格
  7. 保存设置

这三种方法都可以去掉Typecho的index.php,还有问题可以评论区留言。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注