手机版 网站建设 网站设计 网站开发 网站制作 16年专业品质
  • 微信
    微信二维码
  • 微博
  • 商城

Windows Server 上安装部署 WordPress(5):IIS 下 WordPress 站点的固定 URL 链接格式设置

作者:admin  发布时间:2020-03-16 13:05:16

WordPress 初始化安装完成后,默认的 Url 链接格式是:https://blog.codeusing.com/index.php/%year%/%monthnum%/%day%/%postname%/,这是一种“比较好的链接”,但不是“漂亮的链接”、“友好的链接”。最常见、最通用的漂亮友好链接格式如下:

  1. #1 包含分类目录、Url 别名:
  2. https://blog.codeusing.com/category/post-name/
  3. #2 只包含 Url 别名
  4. https://blog.codeusing.com/post-name
  5. #3 包含年、月、日、Url 别名:
  6. http://example.com/year/month/day/post-name

与漂亮友好的链接格式相比,WordPress  默认“比较好的链接”格式多了 index.php,一般网站都不采用这种格式。通常网站会尽量采用简短、漂亮,对用户、搜索引擎友好的 URL 链接格式。

WordPress.org  官方关于固定链接的说明文档:

WordPress 固定链接设置

登录 WordPress 后台,点 Setting(设置) –> Permalink(固定链接)导航菜单进入固定链接设置界面,可以随意设置想要的链接格式。

Wordpress 固定链接设置 Permalink Settings

IIS WordPress 站点固定链接格式支持

如果 WordPress 是部署在 IIS 上的,想要支持友好的 Url 链接格式,需要安装 URL Rewrite 模块支持。如果没有安装 IIS URL Rewrite,访问没有 “index.php” 格式的文章地址,如 http://demo.wordpress.com/hello-world,会报404错误:

Wordpress 固定链接设置 404 错误

下载 IIS URL Rewrite 模块:

打开下载页面后,滚动到页面最下边,可以看到各语言的 MSI 安装包下载,选择需要的下载即可。

微软官方 IIS URL Rewrite 模块下载页面

安装 IIS URL Rewrite 模块:

1. 双击下载好的 .msi 文件,运行安装。

安装 IIS URL Rewrite 模块

2. 安装完成后,打开 IIS,在服务器 Features View(功能视图),可以看到多了一个 URL Rewrite

查看 IIS URL Rewrite 模块

添加 URL 路由规则

上一步安装完 IIS URL Rewrite 后,你如果测试浏览 http://demo.wordpress.com/hello-world,应该还是会报 404 错误。原因是没有添加路由规则。

在 WordPress 网站根目录下,用文本编辑器打开 web.config 文件,在configuration/system.webServer xml 配置节点下添加 rewrite 规则:

  1. <rewrite>
  2. <rules>
  3. <rule name="Main Rule" stopProcessing="true">
  4. <match url=".*" />
  5. <conditions logicalGrouping="MatchAll">
  6. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  7. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  8. </conditions>
  9. <action type="Rewrite" url="index.php/{R:0}" />
  10. </rule>
  11. <rule name="WordPress: demo.wordpress.com" patternSyntax="Wildcard">
  12. <match url="*" />
  13. <conditions>
  14. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  15. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  16. </conditions>
  17. <action type="Rewrite" url="index.php" />
  18. </rule>
  19. </rules>
  20. </rewrite>

Wordpress 添加 IIS URL Rewrite 路由规则

再次测试浏览 http://demo.wordpress.com/hello-world,可以正常访问。搞定!

Wordpress 添加 IIS Url Rewrite 规则后,页面可以正常访问

上一篇: Windows Server 上安装部署 WordPress(4):在 IIS 上部署 WordPress 站点 下一篇: Shopify网站建设,你所要知道的一切!
返回列表
16年专业品质
互联网品牌推广专家
专业的建站、人机交互策划、高端UI设计、移动应用开发公司
业务电话:020/22373839    15915747484
业务QQ:641589319
业务QQ:1375530069
广州总部地址:广东省广州市越秀区先烈中路69号东山广场2904室 邮编:510111
海极网络微信二维码