如何配置服务器支持 URL 重写(伪静态规则)?
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 配置文件:
确保已加载mod_rewrite模块,去掉如下配置行前的#注释符号
LoadModule rewrite_module modules/mod_rewrite.so
将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>