漂亮的网址没有在laravel5.2上工作

时间:2017-01-14 02:17:57

标签: php apache .htaccess laravel pretty-urls

似乎漂亮的网址对我不起作用。我尝试了所有我知道的事情,当你尝试http://wasamar.com.ng/login它会给出 404 Not Found 的响应,但是http://wasamar.com.ng/inde.php/login没问题,我编辑了我的公共/目录 .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>

我做错了什么?

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

感谢所有人的支持,但我看到了我的错误,在/etc/apache2/apache2.conf文件中我没有添加AllowOverride All部分的dirctory标签,当我修复它有效。

相关问题