Laravel应用Apache Rewrite Engine路由冲突问题求助及解决
Laravel路由异常:/publicaties被重写为/public的问题排查与解决
问题情况
使用Laravel开发Web应用,临近完成时遇到路由异常:访问http://example.org/publicaties(荷兰语“publication”)时,被Apache Rewrite引擎错误重写为http://example.org/public。当前使用的是Laravel默认的Rewrite规则配置。
所用Rewrite规则配置
DirectoryIndex index.php <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On # 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] # Send Requests To Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
问题解决
经排查,问题根源在于Laravel对相似名称的路由(如publicaties与publications)存在兼容冲突,修改URL路径后,异常情况消失。
内容的提问来源于stack exchange,提问作者Daan Verhelst
相关产品推荐
相关产品推荐

