如何使用apche 2.4开启Rewrite?

问题描述 投票:0回答:1

系统:Debian 11

阿帕奇版本:2.4

使用的博客系统:Typecho 1.2

站点文件夹目录权限:755

问题:按照网上搜到的教程配置地址重写后,除了首页和后端外,所有访问的页面都是404。

相关教程。

http://forum.typecho.org/viewtopic.php?t=10782

如何为 Apache 2.2 启用 mod_rewrite

我使用以下伪静态规则:

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

.htaccess 文件与index.php 位于同一目录中。

php apache url-rewriting
1个回答
0
投票

执行以下操作,也许有效:

  1. 在 Apache 中启用
    mod_rewrite
    模块并重新启动:
sudo a2enmod rewrite
sudo systemctl restart apache2

  1. 在 Apache 配置中,为站点目录设置
    AllowOverride All
    并重新启动 Apache:
<Directory /var/www/html/your-site-dir>
    AllowOverride All
</Directory>

sudo systemctl restart apache2

  1. 确保
    .htaccess
    位于站点的根目录中,并具有正确的重写规则。
  2. 将目录权限设置为 755,文件权限设置为 644。
find /path/to/your/site -type d -exec chmod 755 {} \;
find /path/to/your/site -type f -exec chmod 644 {} \;

  1. 检查 Apache 错误日志以获取见解。
tail -f /var/log/apache2/error.log

  1. 启用重写规则日志记录并检查日志。
RewriteEngine On
RewriteLogLevel 3
RewriteLog "/var/log/apache2/rewrite.log"

  1. 清除浏览器缓存或使用隐身模式并确保
    Typecho
    兼容且最新,或者作为最后的手段,备份并重新安装 Typecho。
  2. 配置更改后记得重新启动 Apache。
sudo systemctl restart apache2

我希望这会起作用......祝你好运,

#阿帕奇时代

© www.soinside.com 2019 - 2024. All rights reserved.