【问题标题】:HTACCESS Rewrite not working on Ubuntu 14, Apache2HTACCESS 重写在 Ubuntu 14、Apache2 上不起作用
【发布时间】:2014-10-10 20:56:01
【问题描述】:

首先,我不是 Linux 方面的专家,甚至不是 Apache 方面的专家,我习惯于在 Windows 和 WAMP 上工作,您只需在其中单击图标并更改您想要更改的配置。

现在我的 LAMP 工作正常,唯一不工作的是 HTACCESS 重写:

Options -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

这是一个常见的 HTACCESS 设置。

每次我编写 URL:localhost/mysite/services 时都会引发 404 错误。

你必须知道我已经尝试了我在 Stackoverflow 和 Ubuntu 论坛上看到的所有内容。

1) 当我检查 mod rewrite 是否处于活动状态时,它说它是 2) 我在"/etc/apache2/sites-available" 中创建了一个"default.conf" 文件并将其放入:

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        # Uncomment this directive is you want to see apache2's
        # default start page (in /apache2-default) when you go to /
        #RedirectMatch ^/$ /apache2-default/
</Directory>

3) 之后我重启了 apache2 服务

似乎没有任何效果,我很绝望,因为我必须为明天完成这项工作。

编辑

此配置在 Windows-WAMP 和生产服务器 (hostgator) 上工作...我刚刚将所有应用程序粘贴到我的 Ubuntu 笔记本电脑上,在这里,它无法正常工作。

【问题讨论】:

  • 你的 htaccess 在哪里?在根文件夹或mysite 文件夹中?另外,您的index.php 在哪个文件夹中?
  • 是的,先生...它与 index.php 位于同一根文件夹中
  • 对。您有 2 个解决方案。首先是在RewriteEngine On 之后添加这一行RewriteBase /。其次是在规则中的index.php 之前添加一个前导斜杠:RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]。两者是等价的
  • 谢谢@JustinIurman,但它不起作用...仍然显示 404 错误

标签: .htaccess ubuntu redirect apache2 lamp


【解决方案1】:

我在 Ubuntu 14 中使用 apache2,这对我来说很好。

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|public|hme|img|editor|tsd|wd|images|edi|js|fonts|assets|robots\.txt|css|blog)
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-31
    • 2014-12-01
    • 2013-12-16
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 2013-07-12
    • 1970-01-01
    相关资源
    最近更新 更多