簡體   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