Wordpress修改固定链接
相信很多朋友在采用了新版的wordpress或者更换空间的时候都遇到了这样的问题,当重新设置固定链接时,除了首页,其他页面全部链接无效。伪静态的链接对搜索引擎比较友好,所以在一开始的时候设定好固定的规则,以后会方便许多。我根据几次遇到的情况,整理了一下解决方案,具体如下:
前提:主机支持Mod_rewrite模块(不支持的话就不用尝试了)
Linux主机:
找到网站跟目录下的**.htaccess**文件(它就叫.htaccess,没有其他前缀),如果没看见,有可能是两个原因:
1、被隐藏了,如果网站后台是cpanel等控制面板的话,勾选一下“显示隐藏的文件”。
2、本来就没有该文件,自行创建一个,然后上传到根目录下。
在其中写入:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
保存,然后修改固定链接就能正常访问了。
**Windows主机**:
这一次我用的就是Windows主机,所以一开始还奇怪为什么.htaccess文件上传了还是无效的。
Windows主机使用的是另外一个文件:**[httpd.ini](/httpd.ini),**在这个文件写入:
[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]
以上两种情况我都遇到过,到后来都解决了,如果你也遇到这种情况,尽管试试上面的解决方案吧!