一般的大型网站系统,都依赖伪静态。如果服务器的伪静态没有配置好,访问部分链接就会出现 404 的情况。
在 WordPress 则具体表现为后台“固定链接”选项设置失效。
固定链接-自定义结构
/%post_id%.html
Apache、Kangle伪静态
下载 Apache -Kangle WordPress 伪静态配置文件,解压后将里面的 .htaccess
上传至网站根目录,然后在 WordPress 后台>设置>固定链接https://imotao.com/go/?url=https://pan.lanzou.com/i0k8u4h>拉到最下面点击“保存更改”即可。
Nginx伪静态
打开nginx.conf
或者某个站点的配置环境,比如 imotao.com.conf
(不同的网站配置不一样),在server { }
大括号里面添加下面的代码:
location /
{
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
然后在 WordPress 后台>设置>固定链接>拉到最下面点击“保存更改”即可。
IIS伪静态
这里强烈不推荐使用 Windows+IIS 建站,因为坑太多!
IIS 的版本不同,伪静态的设置方式也不一样。
如果你的站点根目录有 web.config
文件,则打开 web.config
,在 system.webServer
里加入如下代码:
- <rewrite>
- <rules>
- <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>
然后在 WordPress 后台>设置>固定链接>拉到最下面点击“保存更改”即可。
如果你的站点根目录没有 web.config
文件,则试试下面这种方法:
先新建一个 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 后台>设置>固定链接>拉到最下面点击“保存更改”即可。
IIS另类方法
其实还有一种另类的方法,不过不推荐使用此方法,治标不治本。
在网站根目录建立一个 404.php 文件。然后打开编辑,插入如下代码:
- <?php
- $qs = $_SERVER[‘QUERY_STRING’];
- $_SERVER[‘REQUEST_URI’] = substr($qs, strpos($qs,’:80′)+3);
- $_SERVER[‘PATH_INFO’] = $_SERVER[‘REQUEST_URI’];
- include(‘index.php’);
- ?>
参考资料:http://www.admin5.com/article/20130711/514219.shtml
关于宝塔设置
网站-设置-伪静态-选中wordpress-保存
原创文章,作者:陌涛,如若转载,请注明出处:https://imotao.com/103.html
评论列表(3条)
123
@陌涛:哈哈哈
@456:789 10 JQK