使用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服务器的,其他环境下应该大同小异吧。
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什么的,只通过上述步骤就能搞定。简单吧,一劳永逸,简单粗暴
文章评论
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.
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!
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!
appreciate it a great deal this site will be proper as well as everyday
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.
Spot on with this write-up, I absolutely think
this website needs much more attention. I'll probably be back again to
see more, thanks for the information!
Thanks designed for sharing such a good thought, post is pleasant, thats why i have read it entirely
Remarkable! Its really amazing article, I have got much clear idea regarding from this piece
of writing.
Hi, I do believe this is a great blog. I stumbledupon it ;
) I may revisit yet again since i have book marked it.
Money and freedom is the greatest way to change, may you be rich and continue to help
other people.
Hello, Neat post. There's an issue along with your site in web
explorer, would check this? IE nonetheless is the market chief and
a big component of other people will leave out your great writing
due to this problem.
Heya i'm for the primary time here. I came across this board and I find It really useful & it helped me out much.
I hope to present one thing again and help others like you aided me.