WordPress伪静态规则(IIS/Apache/Nginx )
文章最后更新时间:2022年04月08日已超过295天没有更新。
很多个人站长使用WordPress来搭建个人网站,开启了伪静态链接后内页出现404,这个是因为web环境上没有设置伪静态规则导致的,今天阿豪分享下IIS/Apache/Nginx 环境下如何设置伪静态规则
教学内容
首先登入WordPress管理后台 >> 设置 >> 固定链接
IIS伪静态规则
在根目录下新建一个web.config将下面的代码添加到文件中
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers accessPolicy="Read, Script"/> <httpErrors> </httpErrors> <staticContent> </staticContent> <rewrite> <rules> <rule name="WordPress: http://demo.ahaoyw.com" 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>
PS:http://demo.ahaoyw.com为网站域名
Apache伪静态规则
在网站根目录下新建一个 htaccess.txt 文件,添加下面的代码,然后重命名为 .htaccess
RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
Nginx伪静态规则
在站点配置文件中的 server { } 大括号里面添加下面的代码
location / { try_files $uri $uri/ /index.php?$args; }
保存,重启 Nginx 即可
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作有参考学习价值
喜欢请点击上方【分享】,如果对您有帮助可点击上方【打赏】打赏本站。谢谢大家对阿豪运维笔记的支持。