.htaccess - HTACCESS 重写在 Ubuntu 14、Apache2 上不起作用

标签 .htaccess ubuntu redirect apache2 lamp

首先,我不是 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 设置。

每次我写网址:localhost/mysite/services它会引发 404 错误。

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

1)当我检查mod重写是否处于事件状态时,它说它是
2) 我创建了一个 "default.conf"文件在 "/etc/apache2/sites-available"并将其放入:
<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 笔记本电脑上,在这里,它不起作用。

最佳答案

我在 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>

希望这可以帮助。

关于.htaccess - HTACCESS 重写在 Ubuntu 14、Apache2 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25354932/

相关文章:

php - 重写规则重定向文件夹

c - O_RDWR 终端未声明

python - 如何在 Ubuntu 上使用 py2exe(或 pyinstaller)创建 .exe

redirect - 当 url 没有尾部斜杠时,AWS s3 强制 302 重定向 - 需要 301s

redirect - 在 IIS7 中重写映射 - 不重定向

command-line - 如何将命令的输出重定向到两个文件

php - 使用 .htaccess 文件创建用户友好的 URL

php - 登录和结帐页面需要 SSL 的 Magento index.php [HTTP 404]

apache - .htaccess 仅从站点根目录重定向一级

ubuntu - 在 Ubuntu 中为 Eclipse IDE 聊天