Laravel重写不起作用 [英] Laravel rewrite not working

查看:101
本文介绍了Laravel重写不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在apache2 ubuntu 17.04上进行htaccess重写,但是它不起作用.我想做的是使用localhost/anyroute访问路由,但是访问它的唯一方法是localhost/PROJECTNAME/public/anyroute.localhost/ANYROUTE在Windows上工作,但是apache将在ubuntu上返回找不到所请求的URL",我不知道为什么.这是我的confs文件.htaccess

I'm trying to make htaccess rewrite work on apache2 ubuntu 17.04 however it won't work. what i'm trying to do is access the route with localhost/anyroute but the only way to access it is localhost/PROJECTNAME/public/anyroute. localhost/ANYROUTE works on windows but apache will return "The requested url not found" on ubuntu and i have no idea why.. here are my confs file .htaccess

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

我的虚拟主机

<VirtualHost *:80>
DocumentRoot /var/www/html/test/public/
<Directory /var/www/html/test/public>
Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>
ErrorLog /var/log/apache2/test-error_log
CustomLog /var/log/apache2/test-access_log common
</VirtualHost>

apache2.conf

apache2.conf

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

所以最重要的是localhost/anyroute不起作用,但是localhost/project/public/anyroute将起作用.我几乎尝试了一切:/

so bottom line is that localhost/anyroute won't work but localhost/project/public/anyroute will work. i have pretty much tried everything :/

推荐答案

启用mod_rewrite

现在,我们需要激活mod_rewrite.

Now, we need to activate mod_rewrite.

sudo a2enmod rewrite

这将激活模块或警告您该模块已经生效.要使这些更改生效,请重新启动Apache.

This will activate the module or alert you that the module is already in effect. To put these changes into effect, restart Apache.

sudo service apache2 restart

在开始之前,我们需要设置并保护更多设置.

We will need to set up and secure a few more settings before we can begin.

首先,允许对.htaccess文件进行更改.使用nano或您喜欢的文本编辑器打开默认的Apache配置文件.

First, allow changes in the .htaccess file. Open the default Apache configuration file using nano or your favorite text editor.

sudo nano /etc/apache2/sites-enabled/000-default.conf

在该文件内,您将在第1行找到该块.在该块内,添加以下块:

Inside that file, you will find the block on line 1. Inside of that block, add the following block:

/etc/apache2/sites-available/default
<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

您的文件现在应与以下内容匹配.确保所有块都正确缩进.

Your file should now match the following. Make sure that all blocks are properly indented.

/etc/apache2/sites-available/default
<VirtualHost *:80>
    <Directory /var/www/html>

        . . .

    </Directory>

    . . .
</VirtualHost>

要使这些更改生效,请重新启动Apache.

To put these changes into effect, restart Apache.

sudo service apache2 restart

现在,创建.htaccess文件.

Now, create the .htaccess file.

有关详细信息,请参见下面的参考链接:

For Detail Follow Below Reference Link :

https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04

这篇关于Laravel重写不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆