【发布时间】:2018-07-30 16:35:39
【问题描述】:
我想在切换到 Laravel 后支持旧网址。
由于不允许在路由中使用点 .,因此我尝试在 public/.htaccess 文件中将 user.php?id=3 重定向到 /user/3。
我试过了
RewriteCond %{QUERY_STRING} id=(.*)
RewriteRule ^user\.php$ /user/$1
但它不起作用。 RewriteRule 被忽略。有什么建议为什么会被忽略?
这是我完整的 Laravel .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{QUERY_STRING} id=(.*)
RewriteRule ^user\.php$ /user/$1
# 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]
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]
# 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>
【问题讨论】:
-
"由于不允许在路由中使用点 ." 路由中允许使用点,但路由变量中不允许使用点。不需要所有的重定向
-
@kerbholz 我希望你是对的!如果我尝试
Route::get('/user.php',function(){ dd('test'); })然后/user.php返回No input file specified. -
嗯,奇怪。
Route::get('/user.py', function () {dd('test');});在这里就像一个魅力,使用Laravel Framework 5.5.28并且没有 Apache,所以 NO RewriteRules。 -
@kerbholz 好的,我发现了问题 - 它可以在我的 apache 制作服务器上运行,但它不能在带有 Nginx laracasts.com/discuss/channels/general-discussion/… 的 Homestead 上运行......谢谢你的评论.. 我只需要我的生产服务器工作。
-
很好,很高兴它有效