当前位置:首页 > WordPress教程 > 正文

WordPress各种伪静态规则大全(IIS6/IIS7.5/Apache/Nginx/win2003/win2008)

不少朋友总是询问 WordPress 如何添加伪静态规则,今天幻杀就总结一下 IIS6/IIS7.5/Apache/Nginx/win2003/win2008四种环境下的伪静态规则,希望对大家有所帮助。其中IIS7.5的规则是目前最完美的哦

明明是六种为什么要说是四种呢?其实windows的主机在2003时为IIS6,而2008以后升级为了IIS7.5 所以IIS6的规则在IIS7.5不通用哦,其实我以前也很纠结的。弄了半天规则才发现,悲催了

检测主机是否支持伪静态的方法:在WP后台 > 设置 > 固定链接,设置为 非默认带?的那种结构,然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 WordPress 伪静态。

url-huan

IIS7.5完美伪静态规则

IIS 环境是 Windows 主机常用的服务器环境,但网上很多规则其实并不完美,很多地方依旧有些无法设置的地方,但这个却可以,新建两个 txt 文件,将下面的代码分别添加到文件中:

第一个 web.config

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ChineseURL" stopProcessing="true">
<match url="^(tag|category)/(.*)$" />
<action type="Rewrite" url="ihuanurl.php"/>
</rule>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

第二个辅助文件 ihuanurl.php:

<?php

// IIS Mod-Rewrite
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
}
// IIS Isapi_Rewrite
else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
else
{
// Use ORIG_PATH_INFO if there is no PATH_INFO
if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];

// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
if ( isset($_SERVER['PATH_INFO']) ) {
if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
else
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
}

// Append the query string if it exists and isn't null
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}

require("index.php");

?>

然后保存文件,上传到WordPress站点的根目录即可。

IIS6伪静态规则

IIS 环境是 Windows 主机常用的服务器环境,新建一个 txt 文件,将下面的代码添加到文件中:

[ISAPI_Rewrite]
# Defend your computer from some worm attacks
#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
# 3600 = 1 hour

CacheClockRate 3600
RepeatLimit 32
 
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through

RewriteRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /software-files/(.*) /software-files/$1 [L]
RewriteRule /images/(.*) /images/$1 [L]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]


然后另存为 httpd.ini 文件,上传到WordPress站点的根目录即可。

Apache伪静态规则

Apache是 Linux 主机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

然后上传到 WordPress 站点的根目录,重命名为 .htaccess 即可

Nginx伪静态规则

Nginx环境一般是Linux 主机 VPS或服务器用户用的比较多,这些用户一般都会自己配置Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,比如 wpdaxue.com.conf(不同人配置的不一样),在  server   { } 大括号里面添加下面的代码:

location / {
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;
        }
}

保存,重启 Nginx 即可。

最后来个结尾:你们会问我我为什么知道IIS7.5的规则,其实以前我就是用的win2008的机子,但是用来做博客的话,win主机真的不大适合,绝大部分运营商都会禁止smtp的,而且win主机运行php实在是太慢了,推荐在win的主机上安装阿帕奇之后再用,真的,我不想深受其害了

标签:
上一篇: 下一篇:

716 条评论

评论加载中...
  1. Hello to all, it’s really a good for me to pay a quick visit this site, it includes priceless Information.

    2018年8月15日 17:52 评论
  2. Hi are using WordPress for your blog platform? I’m
    new to the blog world but I’m trying to get started and set up
    my own. Do you need any coding expertise to make your own blog?
    Any help would be really appreciated!

    2018年8月15日 17:50 评论
  3. I think this is among the most vital information for me.
    And i am glad reading your article. But wanna remark on few general things, The web site style
    is ideal, the articles is really nice : D. Good job,
    cheers

    2018年8月15日 17:29 评论
  4. Hey there! Do you use Twitter? I’d like to follow you
    if that would be okay. I’m definitely enjoying your blog and look forward to new posts.

    2018年8月15日 17:03 评论
  5. Touche. Outstanding arguments. Keep up the amazing work.

    2018年8月15日 16:40 评论
  6. 555楼
    Russian Federation 谷歌浏览器 Windows 7
    Annie  

    I’ve been browsing online more than 4 hours today, yet I never found any interesting article like
    yours. It’s pretty worth enough for me. In my view,
    if all website owners and bloggers made good content as you did, the internet will be
    a lot more useful than ever before.|
    I couldn’t resist commenting. Very well written!|
    I’ll immediately take hold of your rss as I can’t in finding your email subscription link or newsletter
    service. Do you have any? Kindly allow me realize so that I could subscribe.
    Thanks.|
    It is the best time to make some plans for the future and it’s time
    to be happy. I’ve read this post and if I could I want to
    suggest you few interesting things or advice. Maybe you could write next articles referring to this article.
    I want to read even more things about it!|
    It’s appropriate time to make some plans for the long run and it’s time to be happy.
    I have read this submit and if I could I want to counsel you few attention-grabbing things or
    tips. Perhaps you can write next articles relating to this article.
    I desire to read more things approximately it!|
    I have been surfing online greater than 3 hours these days,
    but I never discovered any interesting article like yours.
    It is beautiful price sufficient for me.
    In my opinion, if all site owners and bloggers made good content material as you did, the web will probably be
    much more helpful than ever before.|
    Ahaa, its pleasant discussion regarding this post here at this weblog, I have read all that, so at this
    time me also commenting at this place.|
    I am sure this post has touched all the internet people, its really really fastidious
    post on building up new weblog.|
    Wow, this post is fastidious, my sister is analyzing
    these things, therefore I am going to tell her.|
    Saved as a favorite, I like your website!|
    Way cool! Some very valid points! I appreciate you penning this article and the rest of the website
    is really good.|
    Hi, I do think this is a great blog. I stumbledupon it ;)
    I will return yet again since I book-marked it.
    Money and freedom is the greatest way to change, may you be rich and
    continue to guide other people.|
    Woah! I’m really enjoying the template/theme of this website.

    It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between user friendliness and visual appeal.
    I must say you have done a amazing job with this.
    Additionally, the blog loads very quick for me on Internet explorer.
    Outstanding Blog!|
    These are actually great ideas in on the topic of
    blogging. You have touched some nice points here.
    Any way keep up wrinting.|
    Everyone loves what you guys are up too. This type of clever work and reporting!
    Keep up the good works guys I’ve you guys to my personal blogroll.|
    Hey there! Someone in my Facebook group shared this website with us so
    I came to check it out. I’m definitely loving the information. I’m book-marking and will be tweeting
    this to my followers! Great blog and amazing design.|
    Everyone loves what you guys are up too. Such clever work
    and coverage! Keep up the great works guys I’ve included you guys to
    my personal blogroll.|
    Hey would you mind stating which blog platform you’re working with?

    I’m looking to start my own blog soon but I’m having
    a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most
    blogs and I’m looking for something completely unique.
    P.S Sorry for being off-topic but I had to ask!|
    Hi would you mind letting me know which web host you’re working
    with? I’ve loaded your blog in 3 completely different internet browsers and I must say this blog
    loads a lot quicker then most. Can you suggest a good web hosting provider at a reasonable price?
    Many thanks, I appreciate it!|
    I really like it when individuals get together and share thoughts.
    Great site, stick with it!|
    Thank you for the auspicious writeup. It in fact was a amusement account it.
    Look advanced to far added agreeable from you!
    By the way, how could we communicate?|
    Howdy just wanted to give you a quick heads up. The text in your content seem to be running off the screen in Safari.
    I’m not sure if this is a formatting issue or something to
    do with browser compatibility but I thought I’d post to let you know.
    The design look great though! Hope you get the problem solved soon. Cheers|
    This is a topic that’s near to my heart… Thank you!
    Exactly where are your contact details though?|
    It’s very trouble-free to find out any matter on web as compared
    to books, as I found this piece of writing at this web site.|
    Does your site have a contact page? I’m having a tough time locating it but,
    I’d like to send you an e-mail. I’ve got some creative ideas for your blog you
    might be interested in hearing. Either way, great blog and I look
    forward to seeing it develop over time.|
    Hello! I’ve been reading your website for some time now and finally got the courage to go ahead and give you a
    shout out from Kingwood Tx! Just wanted to say keep up the fantastic
    work!|
    Greetings from Colorado! I’m bored at work so I decided to browse your site
    on my iphone during lunch break. I enjoy the info you provide
    here and can’t wait to take a look when I get home. I’m shocked at how quick your
    blog loaded on my cell phone .. I’m not even using WIFI, just 3G
    .. Anyways, very good blog!|
    Its such as you read my thoughts! You appear to know a
    lot approximately this, such as you wrote the
    e book in it or something. I feel that you simply can do with a few p.c.
    to power the message home a little bit, but instead of that,
    that is magnificent blog. A great read. I’ll certainly be back.|
    I visited several websites except the audio quality for audio songs
    existing at this web page is actually wonderful.|
    Hello, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam remarks?
    If so how do you stop it, any plugin or anything you can suggest?

    I get so much lately it’s driving me insane so any assistance is very much appreciated.|
    Greetings! Very useful advice within this article!
    It’s the little changes that will make the largest changes.
    Thanks for sharing!|
    I seriously love your website.. Great colors & theme.

    Did you create this web site yourself? Please reply back as I’m hoping to create my own site and would
    like to learn where you got this from or what the theme is
    called. Thank you!|
    Hi there! This post could not be written much better! Going
    through this post reminds me of my previous roommate!
    He always kept talking about this. I am going to forward this information to him.

    Fairly certain he will have a good read. Thanks for sharing!|
    Amazing! This blog looks just like my old one!

    It’s on a completely different topic but it has pretty much the same layout
    and design. Superb choice of colors!|
    There’s definately a lot to know about this subject.

    I like all of the points you made.|
    You made some good points there. I looked on the web to find out more about
    the issue and found most individuals will go along with your views
    on this site.|
    Hi there, I read your blog like every week. Your humoristic style is
    awesome, keep up the good work!|
    I just couldn’t leave your website before suggesting that I actually enjoyed the standard information an individual supply
    to your guests? Is going to be again continuously to check
    up on new posts|
    I needed to thank you for this very good read!! I certainly enjoyed every bit of it.
    I’ve got you saved as a favorite to check out new things you post…|
    What’s up, just wanted to say, I liked this blog post.

    It was inspiring. Keep on posting!|
    Hello, I enjoy reading all of your article post. I wanted to write a little comment to support
    you.|
    I constantly spent my half an hour to read this web site’s articles or reviews all the
    time along with a mug of coffee.|
    I for all time emailed this webpage post page to all my friends, as if like to
    read it then my friends will too.|
    My coder is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs.

    But he’s tryiong none the less. I’ve been using Movable-type on numerous websites for about
    a year and am concerned about switching to another platform.

    I have heard very good things about blogengine.net.
    Is there a way I can import all my wordpress content into it?
    Any kind of help would be greatly appreciated!|
    Hello there! I could have sworn I’ve been to this website before but after looking
    at some of the posts I realized it’s new to me. Nonetheless, I’m certainly happy I
    came across it and I’ll be bookmarking it and checking back
    regularly!|
    Terrific work! That is the kind of info that are meant to be shared across the
    web. Shame on Google for no longer positioning this put
    up higher! Come on over and talk over with my web site .

    Thanks =)|
    Heya i am for the first time here. I came across this board and I find It really useful & it
    helped me out a lot. I hope to give something back and aid others
    like you helped me.|
    Hello there, There’s no doubt that your web site might
    be having web browser compatibility issues. When I look at your blog in Safari, it looks
    fine however when opening in Internet Explorer, it
    has some overlapping issues. I just wanted to provide you with a quick heads up!
    Apart from that, wonderful blog!|
    A person essentially lend a hand to make significantly
    articles I’d state. That is the very first time I frequented your website page
    and so far? I surprised with the research you made to create this
    actual submit amazing. Excellent job!|
    Heya i am for the first time here. I came across this board
    and I in finding It truly helpful & it helped me out a lot.

    I’m hoping to present something back and aid others such as
    you helped me.|
    Hi! I simply wish to give you a huge thumbs up for your
    excellent info you have right here on this post. I will be returning
    to your website for more soon.|
    I always used to read piece of writing in news papers but now as I am a user
    of web therefore from now I am using net for articles or reviews,
    thanks to web.|
    Your way of describing everything in this post is truly pleasant, all can simply know
    it, Thanks a lot.|
    Hi there, I found your web site by the use of Google whilst searching for a related matter,
    your site came up, it looks great. I’ve bookmarked
    it in my google bookmarks.
    Hello there, just was aware of your blog thru Google, and found that it’s truly informative.
    I am going to be careful for brussels. I will appreciate for those
    who continue this in future. Many other people will probably be
    benefited out of your writing. Cheers!|
    I am curious to find out what blog system you have been using?

    I’m experiencing some small security issues
    with my latest blog and I would like to find something more risk-free.
    Do you have any solutions?|
    I’m extremely impressed with your writing skills and also
    with the layout on your weblog. Is this a paid theme or did you customize it yourself?
    Anyway keep up the nice quality writing, it is rare to see a great blog like this one today.|
    I’m extremely impressed together with your writing skills and also
    with the format in your weblog. Is that this a paid subject or did you
    modify it yourself? Either way stay up the excellent quality writing, it is uncommon to look a nice blog like this one today..|
    Hi, Neat post. There is a problem with your web site in internet explorer, could test this?
    IE still is the marketplace chief and a huge portion of other folks
    will pass over your wonderful writing due to this problem.|
    I’m not sure where you’re getting your information, but great topic.
    I needs to spend some time learning much more or understanding more.
    Thanks for fantastic info I was looking for this info for
    my mission.|
    Hello, i think that i saw you visited my weblog thus i came to “return the favor”.I’m trying to
    find things to improve my web site!I suppose
    its ok to use some of \

    2018年8月15日 16:10 评论
  7. Greetings! This is my first comment here so I just wanted
    to give a quick shout out and say I truly enjoy reading your blog posts.
    Can you suggest any other blogs/websites/forums that go over the same subjects?
    Thanks a ton!

    2018年8月15日 15:17 评论
  8. This info is worth everyone’s attention. How can I find out more?

    2018年8月15日 15:01 评论
  9. Unquestionably believe that which you stated. Your favorite reason seemed to be on the net the simplest thing to be aware
    of. I say to you, I definitely get irked while people think about worries that they plainly don’t know about.

    You managed to hit the nail upon the top and also defined out the whole
    thing without having side-effects , people can take a signal.
    Will probably be back to get more. Thanks

    2018年8月15日 14:45 评论
  10. Hi there! I simply want to give you a big thumbs up for the excellent info
    you have here on this post. I am coming back to your website for more soon.

    2018年8月15日 14:31 评论

发表评论

不理你。不要啊!吃饭。吃惊。吃西瓜。飞吻!恭喜!Hi纠结!膜拜!OK抛媚眼。泡泡糖。抛钱。忍!生闷气!调皮。偷看。委屈。献花。疑问?抓狂!

小提示:Ctrl+Enter快速提交助您一臂之力~
加载中……