Apache、Nginx 二级目录搭建的网站实现伪静态

@ 2021-01-17 18:30:00 技术教程 评论(0) 浏览(4423) 点赞(1) 字数(183)

有很多人用二级目录搭建的网站,不能实现伪静态,这个需求倒是比较常见,很多人可能不太会配置,其实很简单。

Apache

比如说我想在二级目录 www.hurbai.com/typecho 下搭建一个typecho程序,只需要把根目录下的.htaccess复制到 typecho 目录下然后改下就行。

根目录 .htaccess 代码:

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

复制到 typecho 目录后修改:

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /typecho
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

只需要将 RewriteBase / 修改为 RewriteBase /typecho 即可,其他的不需要改动,因为我两个程序都是以 typecho 为例,其他的不同程序请自行修改。

Nginx

根目录伪静态:

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

添加 typecho 目录后修改:

if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php$1 last;
    rewrite ^/typecho/(.*)$ /typecho/index.php?$1 last;
}

也就是添加了一行:rewrite ^/typecho/(.*)$ /typecho/index.php?$1 last
因为我两个程序都是以 typecho 为例,其他的不同程序请自行修改。

本文标签: 伪静态Apache二级目录建站Nginx

本文链接:https://www.hurbai.com/jishu/414

本文最后更新于:2021-01-17 19:11:23,可能因经年累月而与现状有所差异

文章收录情况:加载中