当前位置:首页 > 建站教程 > emlog > 正文内容

如何配置服务器支持 URL 重写(伪静态规则)?

阿坝云1天前emlog349

Nginx服务器

  • 宝塔面板:站点设置 - 伪静态 - 选择emlog的规则 - 点击保存即可

  • 手动配置:修改 Nginx 配置文件在站点相关配置中增加如下规则:

location / {
  index index.php index.html;
  if (!-e $request_filename){
     rewrite ^/(.*)$ /index.php last;
  }
}

Apache服务器

根目录下已经配置了静态规则文件 .htaccess 文件,内容如下:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteBase /
   RewriteRule . /index.php [L]
</IfModule>

如果静态规则没有生效,需要修改Apache服务器配置开启支持.htaccess,检查 http.conf 配置文件:

  1. 确保已加载mod_rewrite模块,去掉如下配置行前的#注释符号

    LoadModule rewrite_module modules/mod_rewrite.so
  2. 将AllowOverride指令设置为All

    AllowOverride All

Windows IIS 服务器

IIS6

找到 httpd.ini 文件(通常位于 C:\Program Files\ISAPI_Rewrite\ 或安装目录下),配置如下内容:

[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
RewriteRule /robots.txt(.*) /robots.txt$1 [L]
RewriteRule /rss.php(.*) /rss.php$1 [L]
RewriteRule /tb.php(.*) /tb.php$1 [L]
RewriteRule /favicon.ico /favicon.ico [L]
RewriteRule /xmlrpc.php(.*) /xmlrpc.php$1 [L]
RewriteRule /wlwmanifest.xml /wlwmanifest.xml [L]
RewriteRule /(t|m)$ /$1/ [R] RewriteRule /(admin|content|include|t|m)/(.*) /$1/$2 [L]
RewriteRule /install.php(.*) /install.php$1 [L]
RewriteRule /up(d.d.d)to(d.d.d).php(.*) /up$1to$2.php$3 [L]
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

IIS7/8/10

在站点根目录创建文件 web.config,填写下面内容即可

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

    <system.webServer>

        <rewrite>

            <rules>

                <rule name="emlog Rewrite" stopProcessing="true">

                    <match url="^(.*)" ignoreCase="false" />

                    <conditions logicalGrouping="MatchAll">

                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />

                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />

                    </conditions>

                    <action type="Rewrite" url="/index.php" />

                </rule>

            </rules>

        </rewrite>

    </system.webServer>

</configuration>


分享给朋友:
返回列表

上一篇:emlog博客搬家教程

没有最新的文章了...

“如何配置服务器支持 URL 重写(伪静态规则)?” 的相关文章

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。