因为WordPress时PHP系统,链接后面都带有?的动态链接,虽然搜索引擎不排斥动态链接,但是传说伪静态后更容易被搜索引擎收录,下面就来说说怎么弄:
进入管理界面,进入”设置”-“固定链接”
进入后选中”自定义结构”,输入/%post_id%.html后并保存设置:
然后根据你的服务器环境写入伪静态文件规则:
Apache规则:
请确保你的根目录开启了777权限,已开启的话,在修改自定义固定链接后的瞬间,会在主机根目录自动生成一个.htaccess的文件,打开查看是否已生成规则,生成的话,就OK了,就不需要往下看了。
如果没有生成.htaccess,或者.htaccess里没有内容,那就需要手动创建一个txt文件,使用上传软件修改名为 .htaccess,粘贴Apache规则代码,保存并上传到网站根目录就行了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> |
Nginx规则:
1 2 3 4 5 6 7 8 9 10 11 | location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } |
windows规则:
windows主机必须安装了装Rewrite 组件才能支持伪静态,如果主机支持伪静态,在修改wordpress固定链接后无法伪静态,在根目录自动生成一个httpd.ini,没有生成的话,就创建一个txt文本,修改名字为httpd.ini,复制粘贴下边代码,保存上传到根目录:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | [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] |
Great content! Super high-quality! Keep it up! 🙂
Nice Web page, Continue the beneficial work. thnx!
Neat Web site, Maintain the great job. Thanks a ton.