WordPress实现伪静态

本文介绍如何在WordPress中设置自定义结构的静态地址,并提供了一种实现方式,通过配置httpd.ini文件来启用WordPress的伪静态规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

点击最下面的  自定义结构   然后输入 /%post_id%.html ,然后保存更改,地址就会变为静态地址了

当然,并没有完

 

继续

复制下面的代码:

[ISAPI_Rewrite]

    # 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 /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 上传到根目录即可,若不行。则复制下面代码替换之前代码

 

[ISAPI_Rewrite]

    # 3600 = 1 hour

    CacheClockRate 3600

    RepeatLimit 32

    # Protect httpd.ini and httpd.parse.errors files

    # from accessing through HTTP

    # wordpress 伪静态规则

    # For tag(中文标签以及标签翻页的规则)

    RewriteRule /tag/(.*)/page/(d+)$ /index.php?tag=$1&paged=$2

    RewriteRule /tag/(.+)$ /index.php?tag=$1

    # For category(中文分类以及分类翻页的规则)

    RewriteRule /category/(.*)/page/(d+)$ /index.php?category_name=$1&paged=$2

    RewriteRule /category/(.*) /index.php?category_name=$1

    # For sitemapxml

    RewriteRule /sitemap.xml /sitemap.xml [L]

    RewriteRule /sitemap.html /sitemap.html [L]

    RewriteRule /sitemap_baidu.xml /sitemap_baidu.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]

 

转载于:https://www.cnblogs.com/fakehydra/p/9622764.html

### WordPress伪静态URL配置方法 对于使用集成环境如宝塔、lnmp、AHM、phpstudy等部署WordPress的情况,通常这些环境已经集成了Wordpress伪静态功能[^1]。然而,在具体设置过程中仍需注意一些细节。 #### 判定服务器是否支持伪静态 在尝试启用伪静态前,先确认主机空间是否支持此特性非常重要。可以通过进入网站后台->设置->固定链接来测试这一点。除了默认选项外选择任意一种结构并保存更改;随后浏览除首页之外的其他页面,观察是否会遇到404错误。一旦发现此类问题即表明当前的空间可能无法正常处理重写规则[^2]。 #### Apache环境下配置伪静态 大多数Linux VPS以及共享托管服务都基于Apache Web Server运行。此时可通过修改`.htaccess`文件实现URL美化效果: ```apache <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> ``` 这段代码片段应当放置于站点根目录下的隐藏文件`.htaccess`内。如果该文件不存在则手动创建之。 #### Nginx环境下配置伪静态 当采用Nginx作为Web服务器时,相应的配置应位于虚拟主机配置文件中而非通过单独的.htaccess文件管理。下面给出了一组适用于Nginx的典型rewrite指令: ```nginx location / { try_files $uri $uri/ /index.php?$args; } ``` 上述配置同样实现了将请求转发至`index.php`的效果,从而允许WordPress解析自定义路径参数。 #### Windows (IIS) 环境下配置伪静态 针对Windows平台上的Internet Information Services(IIS),特别是较新的版本比如IIS 8及以上,可以利用其内置的功能轻松达成目的。具体的步骤涉及安装URL Rewrite Module模块,并按照官方文档指导编写web.config内的相应节点[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值