【wordpress】Wordpress在Apache/Nginx/IIS/Lighttpd环境下的伪静态配置

目录

一、问题说明

二、解决方式

1、Apache

2、Nginx

3、IIS

4、Lighttpd


一、问题说明

解决各种环境下,页面存在但出现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")

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值