目录
一、问题说明
解决各种环境下,页面存在但出现404错误。在Apache,Wordpress在安装过程中自动生成伪静态的代码,所以Apache上面可以不用配置。如果只是直接复制代码进apache上面则需要配置
如果是使用rewrite组件的就在对应文件设置,否则在应用服务器的配置文件添加
1,确认空间支持rewrite组件。
2,按照 伪静态rewrite 目录下的说明文档操作。
3,后台设置浏览模式为 rewrite伪静态 。
二、解决方式
1、Apache
在项目根目录的【.htaccess】文件(如果没有则新建文件),添加如下代码
# BEGIN WordPress
# 在“BEGIN WordPress”与“END WordPress”之间的指令(行)是
# 动态生成的,只应被WordPress过滤器修改。
# 任何对标记之间的指令的修改都会被覆盖。
<IfModule mod_rewrite.c>
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]
</IfModule>
# END WordPress
2、Nginx
注意:如果在项目跟目录的文件配置的话
1.有虚拟主机的话:需要配置vhosts.conf,在里面配置include到对应文件。
2.没有虚拟主机的话:直接在应用服务器的conf配置,在里面include到对应文件。
# 以nginx配置为例
server {
# ///其他配置
location / {
# ///其他配置
include xxx/xxx.htaccess;
}
}
在项目根目录中的【nginx.htaccess】文件(如果没有则新建文件),添加如下代码
location /
{
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
或者下面这个
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;
}
3、IIS
在项目根目录中的【httpd.ini】或【web.config】文件(如果没有则新建文件),添加如下代码
iis6.x 下使用 httpd.ini
[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]
iis7.x 下使用web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
4、Lighttpd
lighttpd是不支持.htaccess的,所以只能在配置文件【lighttpd.conf】中修改
添加如下代码
url.rewrite = ("^/(wp-.+).*/?" => "$0","^/(sitemap.xml)" => "$0","^/(xmlrpc.php)" => "$0","^/(.+)/?$" => "/index.php/$1")