【问题标题】:pretty url not working on laravel5.2漂亮的网址在 laravel5.2 上不起作用
【发布时间】:2017-01-14 02:17:56
【问题描述】:

似乎漂亮的 URL 不适合我。我已经尝试了所有我知道的东西,当您尝试 http://wasamar.com.ng/login 时,它会给出 404 Not Found 的响应,但 http://wasamar.com.ng/inde.php/login 没问题,我已经编辑了我的 public/ 目录的 .htaccess strong> 文件到这个:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

这是 /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerName wasamar.com.ng

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/wasamar/public

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

我做错了什么?

【问题讨论】:

  • 你的 Apache 虚拟主机的根目录是什么?
  • 在哪里可以查到?是你说的 /etc/apache2 吗?
  • 取决于您的操作系统,例如 /etc/apache2/sites-available/ 用于 Debian。
  • Ubuntu 服务器 16.04 是的,它是 /etc/apache2/sites-available/
  • 那么...你的 Apache 虚拟主机的根目录是什么?

标签: php apache .htaccess laravel pretty-urls


【解决方案1】:

这可能是因为您的 apache 重写模块未启用。在 Ubuntu 机器上启用重写模块:

sudo a2enmod rewrite
sudo service apache2 restart

如果您的平台上没有a2enmod,您需要打开您的httpd.conf 文件并取消注释包含rewrite_module 的行。在 macOS 机器上是这样的:

LoadModule rewrite_module libexec/mod_rewrite.so

那你需要重启服务。

此外,要使 htaccess 文件生效,您需要将 AllowOverride 指令设置为 All。这是一个例子:

<Directory "/absolute/path/to/webserver/root">
    # ...

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    # ...
</Directory>

【讨论】:

  • 我已经这样做了 sudo a2enmod rewrite 但问题仍然存在。
【解决方案2】:

感谢大家的支持,但我看到了我的错误,在/etc/apache2/apache2.conf 文件中,当我修复它的工作时,我没有添加AllowOverride All 部分的目录标签。

【讨论】:

  • 是的,在某种程度上,你说的是 .htaccess 但我在 .apache2.conf 文件中修复了它。
  • 不,我没有。引用:for htaccess files to be effective you need to set AllowOverride directive to All..
  • 是的,你做了,但你忘了说明文件来修复错误。
  • 是的,你是对的。我想这很清楚,因为它只能在主配置文件中配置。
猜你喜欢
  • 2015-10-17
  • 2017-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-11
  • 2015-11-24
  • 2015-06-01
  • 1970-01-01
相关资源
最近更新 更多