【问题标题】:mod_rewrite not working in Laravel 5mod_rewrite 在 Laravel 5 中不起作用
【发布时间】:2018-05-16 18:22:16
【问题描述】:

使用 Laravel 5.5 时,尝试访问 http://127.0.0.1:8000/test/search/357 时出现找不到页面错误。没有其他解决方案对我有用。我的 .htaccess 文件位于根目录中,如下所示:

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

Options +FollowSymLinks
RewriteEngine On

RewriteBase "/test/"

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

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


RewriteRule ^/test/search/(.*)$ /test/search?m_id=$1&a=1 [QSA, L]

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

任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 您有语法错误。您打开 IfModule 两次但只关闭一次。除此之外,我认为在 laravel 中使用 htaccess 重定向而不是路由并正确设置虚拟主机并不是一个好主意。

标签: php apache laravel .htaccess mod-rewrite


【解决方案1】:

你可以使用:

RewriteRule ^test/search/(.*)$ /test/search?m_id=$1&a=1 [QSA, L]

在htaccess RewriteRule中没有左/
并将规则放在#Handle Front Controller 之前

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 2016-12-19
    • 2016-05-17
    • 2015-05-07
    • 1970-01-01
    • 2016-01-30
    • 2012-12-15
    相关资源
    最近更新 更多