請根據自己的環境選擇僞靜态規則.
有的朋友不知道自己是什麼環境的, 可以通過管理者背景首頁檢視


通常大家用的環境都是 IIS, APACHE ,NGINX (還是補充個小寫吧 iis, apache, nginx)
大部分國内空間用的都是 IIS 以及 APACHE
而且都有切換PHP版本的功能, 我建議大家将PHP版本提升到最高.
Apache僞靜态
Apache的僞靜态是最簡單 易用的.
直接在網站根目錄下建立檔案:.htaccess (注意: 不要在前面加什麼 x.htaccess . 該檔案不需要檔案名 隻需要字尾)
寫入内容:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>
如果完成以上操作 依然無法使用. 那可能是你的Apache為開啟僞靜态子產品
在Apache 安裝目錄中找到conf/httpd.conf檔案
在該檔案中搜尋 : mod_rewrite
即可找到關鍵字
#LoadModule rewrite_module modules/mod_rewrite.so
如果你看到 前面有一個# 号 說明僞靜态子產品并未開啟
是以你需要将 #号去除, 儲存檔案 重新開機Apache程序即可! 不會重新開機Apache的 請重新開機主機吧!
Nginx
Nginx的僞靜态安裝時比較麻煩的, 因為Nginx一般會在Linux下安裝使用, 空間以及Windows用的較少.
你需要來到Nginx的Conf目錄
這裡用LNMP的安裝目錄作為說明
LNMP中的Nginx目錄在 /usr/local/nginx中
# cd /usr/local/nginx/conf/vhost
在目錄中找到你的網站目錄vhost
(這裡可能有人不了解 我也不知道怎麼說的明白)
# vi 你的目錄名.conf
打開檔案後可見内容:
server
{
listen 80;
#listen [::]:80;
server_name http://bbs.hyphp.cn bbs.hyyyp.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/bbs.hyphp.cn;
include other.conf;
#error_page 404 /404.html;
include enable-php.conf;
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 12h;
}
......
........
...
省略..
在中間插入:
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
server
{
listen 80;
#listen [::]:80;
server_name http://bbs.hyphp.cn bbs.hyyyp.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/bbs.hyphp.cn;
include other.conf;
#error_page 404 /404.html;
include enable-php.conf;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 12h;
}
插入後就是上面的結構了
儲存該Conf即可
重新開機Nginx 完成
IIS 7 以上
IIS7版本以上安裝了URL重寫支援才會支援Web.config僞靜态
在根目錄寫入以下内容 儲存為 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?s={R:1}" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="false" />
<security>
<requestFiltering allowDoubleEscaping="True" />
</security>
</system.webServer>
</configuration>
IIS6
IIS6 是不支援web.Config的 是以你需要使用 ISAPI_Rewrite.dll 進行解析httpd.ini 那請用你的方法 将httpd.ini内容 配置到 IIS中
httpd.ini
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
RewriteRule (.*)$ /index.php?s=$1 [I]
如果你的空間支援 httpd.ini的話 那就在根目錄中建立 httpd.ini這個檔案 并寫入上面的内容.并且你需要删除根目錄下的 Web.config檔案
如果你的IIS使用Web.config 那你就可以直接使用 根目錄提供的Web.config檔案
配置完成以及 程序或伺服器 重新開機後 請回到管理者背景首頁 檢視伺服器資訊
如果提示 僞靜态條件 為支援. 則可以開啟僞靜态
去掉?号 打開檔案 /Conf/config.php 找到内容: //'REWRITE'=>1,//僞靜态規則
去掉前面的 //
改為下圖所示内容
儲存檔案即可!
僞靜态安裝完畢