常用WordPress伪静态规则(Nginx/Apache/IIS) 附固定链接设置技巧
WordPress伪静态设置规则
如果有服务器环境和WEB环境自带的,那我们直接用系统自带规则,如系统没有自带,则需要什么手工部署。
1、Apache
一般我们虚拟主机会用到Linux Apache环境,这个伪静态文件在我们网站根目录 .htaccess 文件中,我们需要添加。
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
2、Nginx
Nginx 是我们比较常用的WEB引擎。如果系统没有自带配置,我们需要自己配置。
location / { try_files $uri $uri/ /index.php?$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $scheme://$host$uri/ permanent;
3、IIS
IIS 是我们常用的Windows系统引擎,一般我们很少用WIN用来搭建WP程序,因为WP兼容比较好的是LiNUX系统。
[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]
这需要配置到IIS系统站点的httpd.ini文件中生效。
第二、WordPress固定链接设置
我们很多朋友都知道如何设置固定链接,当前如果用动态链接不利于搜索引擎和用户体验,现在大家都用伪静态或者静态链接。
我们可以看到上图,在【设置】-【固定链接】然后我们可以选择固定给的日期和名称类型、月份和名称类型、数据型、文章名型的链接样式。或者我们可以根据实际需要设置,我们可以自定义结构。比如小编用的是 ID.html 格式。
这里有个提醒,我们在创建网站后设置固定链接,以后尽量不去修改链接,甚至以后都不要修改。必须考试就考虑好。
本文链接:https://yun.ha.cn/post/32.html 转载需授权!