【问题标题】:Apache mod_rewrite is enable on server but not working?Apache mod_rewrite 在服务器上启用但不工作?
【发布时间】:2017-01-29 12:45:18
【问题描述】:

我最近安装了灯组并启用了 mod_rewrite:

$ sudo a2enmod rewrite
$ service apache2 restart

我可以在我的 phpinfo 上看到它:

但是当我尝试在我的 WordPress 中访问下面这样的 URL 时:

http://my-localhost/my-wordpress/whats-on/

我收到此错误:

找不到

在此找不到请求的 URL /my-wordpress/whats-on/ 服务器。

Apache/2.4.18 (Ubuntu) 服务器位于 127.0.0.1 端口 80

我还能做什么?我错过了什么吗?

有什么想法吗?

我也有我的 .htaccess:

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

# END WordPress

但是为什么呢?

编辑:

我创建了一个简单的测试:

RewriteRule ^test.html$ test.php [L] 

但我得到 404 错误,而不是被定向到 test.php

Not Found

The requested URL /mod_rewrite/basic/test.html was not found on this server.

Apache/2.4.18 (Ubuntu) Server at 127.0.1.1 Port 80

我该如何解决这个问题?

【问题讨论】:

  • 也许.htaccess 文件被忽略了?首先添加一个简单的重写规则,例如:RewriteRule ^test.html$ test.php [L] 并确保创建了一个 test.php 文件。
  • @OfirBaruch 是的,我认为你是对的。刚刚用你的建议进行了测试,我得到 404 错误而不是被定向到 test.php 那么我该如何解决这个问题?
  • 您是否在主配置中设置了AllowOverride all
  • @cen aww 我没有!现在工作。谢谢。
  • 您检查过文件权限吗?并且图像中的 http_host 是 127.0.1.1 而不是 127.0.0.1。是故意的吗?

标签: php wordpress apache


【解决方案1】:

要解决此问题,请按照以下步骤操作:

sudo nano /etc/apache2/apache2.conf

查找:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

替换为:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

退出并保存并使用命令重启apache

sudo systemctl restart apache2

结束 :-)

【讨论】:

    猜你喜欢
    • 2016-01-16
    • 1970-01-01
    • 2011-03-02
    • 2011-12-10
    • 2011-08-12
    • 1970-01-01
    • 2014-01-11
    • 2017-09-29
    • 2021-10-02
    相关资源
    最近更新 更多