小Q的博客

  • 首页
  • net编程
    • 产品和框架
    • 开发实例
    • 经验技巧
    • 开源组件
  • wp独立站
  • 自媒体
  • 日记本
  • 工具箱
每个程序员,都应该有一个自己的博客站
  1. 首页
  2. wp独立站
  3. 正文

WordPress的固定链接,如何去掉index.php和category

2022年8月26日 7389点热度 0人点赞 5条评论

使用WordPress搭建网站时,如果你是基于IIS服务器搭建的,肯定会遇到这个问题,就是固定链接设置好后,网址会出现烦人的index.php和category这两个关键字。

 

举个例子,博客的分类是wordpress,博客的固定链接是how-to-create-wordpress.html。那么完整的地址就是

  • https://yourwebsite/wordpress
  • https://yourwebsite/wordpress/blog1.html

 

这么看着多友好,一目了然就知道博客在什么分类下,博客的内容是什么?结果非要搞成下面这样。感觉就一个字:low

  • https://yourwebsite/index.php/category/wordpress
  • https://yourwebsite/index.php/category/wordpress/blog1.html

 

解决方法也简单,按照这个步骤就可以。需要注意的是,我是基于IIS服务器的,其他环境下应该大同小异吧。

Table of Contents

Toggle
  • 1、创建404的php文件
  • 2、复制网站根目录下
  • 3、固定链接的设置分类前缀

1、创建404的php文件

代码如下

<?php
$qs = $_SERVER['QUERY_STRING'];
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['REQUEST_URI'] = substr($qs, $pos);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>

 

2、复制网站根目录下

将文件复制到网站根目录下,即可index.php同一文件夹下

  • 打开“错误页”模块,找到404的设置项

  • 修改404指定页面

修改成我们刚才创建的404.php页面,注意前面一定要有/

3、固定链接的设置分类前缀

设置成一个半角的句号,即“.”

 

经过上面的操作,就能去掉那2个烦人的小尾巴了。这个方法的好处是不用设置301、310、410什么的,只通过上述步骤就能搞定。简单吧,一劳永逸,简单粗暴

标签: wordpress 去掉category 去掉index.php 固定链接
最后更新:2022年9月23日

小Q

80后中年不油腻大叔,喜欢编写代码、打羽毛球、做木制玩具。目前定居浙江杭州

打赏 点赞
< 上一篇
下一篇 >

文章评论

  • marijuana

    Pretty element of content. I simply stumbled upon your blog
    and in accession capital to claim that I get in fact enjoyed account
    your weblog posts. Anyway I'll be subscribing to your feeds
    or even I fulfillment you get entry to consistently fast.

    2023年2月13日
    回复
  • nikelab socks

    I like the valuable information you provide in your articles.

    I will bookmark your blog and check again here regularly.
    I'm quite sure I'll learn plenty of new stuff right here!
    Best of luck for the next!

    2023年2月15日
    回复
  • burberry swim sale

    Magnificent web site. Plenty of helpful info here.

    I'm sending it to a few buddies ans also sharing in delicious.

    And naturally, thanks to your effort!

    2023年3月10日
    回复
  • עיסוי אירוטי

    appreciate it a great deal this site will be proper as well as everyday

    2023年3月23日
    回复
  • jakarta timur

    Hey I know this is off topic but I was wondering if you knew of any
    widgets I could add to my blog that automatically tweet my newest twitter updates.
    I've been looking for a plug-in like this for quite some
    time and was hoping maybe you would have some experience with
    something like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look
    forward to your new updates.

    2023年3月24日
    回复
  • razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
    取消回复

    COPYRIGHT © 2022 小Q的博客. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    浙ICP备2022019157号-2