Apache 2.4 无法开启地址重写,求仁兄帮助我解惑

2022-02-19 18:18:41 +08:00
 OwO233
系统:Debian 11
Apache 版本:2.4
使用的博客系统:Typecho 1.2
网站文件夹目录权限:755
遇到的问题:按照网络上搜索的教程配置好地址重写之后,除了首页和后台,其他网页访问全部 404 。
相关教程:
http://forum.typecho.org/viewtopic.php?t=10782
https://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2
我使用的伪静态规则:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

.htaccess 文件和 index.php 同目录。
求仁兄帮助。
1132 次点击
所在节点    问与答
14 条回复
ysc3839
2022-02-19 19:36:21 +08:00
建议改用 nginx
westoy
2022-02-19 19:50:41 +08:00
凭着我十几年前用 apache 1.3 的残存记忆,IfModule 标签是 httpd.conf 里的, 不是.htaccess 的......
Windelight
2022-02-19 19:53:40 +08:00
.htaccess 是否在 httpd.conf 里定义? vhost 和 httpd.conf 是否给了权限?什么地方安装的?
cathiabi
2022-02-19 20:21:16 +08:00
rewrite 的 mod 有没有启用啊
OwO233
2022-02-19 21:02:30 +08:00
@ysc3839 #1 感谢您的回复。因为这边找人写的防火墙是 Apache2 系统的,所以不是很好换系统。
OwO233
2022-02-19 21:07:52 +08:00
@westoy #2 感谢您的回复。2.4 版本的没有 httpd.conf 这个文件啦,改为 apche2.conf 了,并且里面的参数也有改动。这边是从官方的文档里看的配置。
@Windelight #3 感谢您的回复。您好,没有 httpd.conf 文件,apache2.4 是 apache2.conf 文件。AllowOverride 的值全都改成了 All 。
@cathiabi #4 感谢您的回复。您指的是什么呢?
cathiabi
2022-02-19 21:23:11 +08:00
@OwO233 a2enmod 看一下 mod_rewrite 和其他可能相关的模块是否有正确启用,注意启用后需要重启 apache2 服务才能生效
OwO233
2022-02-19 21:52:17 +08:00
@cathiabi #7 您好,感谢您的回复。这版检查过了,是开启的。我认为是服务器没有读取我放在网站根目录的“.htaccess”没有被扫描和执行,但是我给的权限是“755”应该是可以执行的呀。OwQ
a2enmod rewrite
Module rewrite already enabled
cathiabi
2022-02-19 21:58:11 +08:00
@OwO233 那样的话应该是在网站配置那边需要设置 AllowOverride
Windelight
2022-02-19 22:12:21 +08:00
@OwO233 你直接开一个网站,把 ErrorLog 打开,LogLevel 开到 debug ,然后看一下错误是什么
steley
2022-02-19 22:27:50 +08:00
/etc/apache2/apache2.conf 文件里试试

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
OwO233
2022-02-19 23:54:56 +08:00
@cathiabi #9 您好,这边需要看一下我的配置文件吗?
@Windelight #10 感谢您的回复。我试试。
@steley #11 感谢您的回复,我发一下我的配置。

```
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
```
steley
2022-02-20 00:01:28 +08:00
.htaccess 文件是 755 吗?改成 644 试呢?
Apache 重启一下呢
steley
2022-02-20 00:02:38 +08:00
这是我的
-rw-r--r-- 1 www-data www-data 195 Apr 22 2020 .htaccess
OwO233
2022-02-20 02:10:03 +08:00
@steley #13 感谢您的回复。emm ,5 就包含读取了呀,OwQ 。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/835066

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX