Laravel:.htaccess中的RewriteRule不起作用

时间:2018-02-19 15:18:54

标签: .htaccess laravel-5

在我的Laravel应用程序中,我在/public/.htaccess/文件中添加了一个像这样的RewriteRule:

RewriteRule ^resources/pdf/?$ /about 

但是,如果我拨打www.mydomain.com/resources/pdf/,我只会收到此错误:

enter image description here  虽然我的服务器使用APACHE,但其他htaccess条目确实有效。 www.mydomain.com/about也可以。

为什么这不起作用?这是完整的htaccess文件:

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

    RewriteEngine On

    RewriteRule ^resources/pdf/?$ /about [L]

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Now, rewrite any request to the wrong domain to use www.
    # [NC] is a case-insensitive match
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]



    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

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



</IfModule>

2 个答案:

答案 0 :(得分:1)

尝试:

RewriteRule ^resources/pdf/?$ about [NC]

适用于www.mydomain.com/resources/pdf/www.mydomain.com/resources/pdf

答案 1 :(得分:0)

我错过了[L]

 RewriteRule ^resources/pdf/?$ /about [L] 

此外,我必须清除缓存并以隐身模式查看页面以见证效果。