第一步,启用mode_rewrite

首先,要启用apache的mod_rewrite。命令如下:

sudo a2enmod rewrite

启用后显示如下:

a2enmod rewrite

第二步,设置.htaccess

.htaccess是apache的伪静态规则,在默认的情况下,apache会禁用.htaccess文件重写规则,所以首先要修改apache配置文件。NanoPi_NEO修改命令如下:

sudo vi /etc/apahce2/sites-available/000-default.conf

在上面文件中输入i进行编辑,在<VirtualHost*:80>块中,添加如下配置,需要确保块缩进正确。

<VirtualHost *:80>
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    . . .
</VirtualHost>

第三步,以上两步完成后,重启apache

sudo systemctl restart apache2

第四步,添加.htaccess规则

通过以上三步完成后,apache就开启了伪静态重写功能,但是还需要对网站的伪静态规则进行添加,才能正常使用伪静态。

/var/www/html文件夹下面添加.htaccess文件。

sudo vi /var/www/html/.htaccess

Typecho伪静态规则如下:

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

第五步,Typecho开启地址重写功能

在Typecho后台http://localhost/admin/options-permalink.php中的永久链接设置中启用地址重写功能即可。

地址重写

然后设置文章路径风格后保存设置。

标签: NanoPi_NEO, Typecho, apache

添加新评论