繁体   English   中英

漂亮的 url 不适用于 laravel5.2

[英]pretty url not working on laravel5.2

看起来漂亮的 URL 对我不起作用。 我已经尝试了我所知道的一切,当您尝试http://wasamar.com.ng/login它会给出404 Not Found的响应,但http://wasamar.com.ng/inde.php/login没问题,我已将我的 public/ 目录的.htaccess文件编辑为:

<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 重写模块未启用。 要在 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>

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM