[英]The Laravel named route method doesn't generate host server's (apache) alias when generating the URL on view
I wanted to send an email with a button with link to the page I wanted to redirect the recipient to.我想发送一封带有按钮的电子邮件,其中包含指向我想将收件人重定向到的页面的链接。 I have this named route on my
web.php
route file:我的
web.php
路由文件中有这个命名路由:
Route::get('/', [ProbationPeriodController::class, 'index'])->name('Probation.index');
and I added this code for the button on my email view:我为电子邮件视图上的按钮添加了以下代码:
<a href="{{route('Probation.index')}}" target="_blank">Take Action</a>
I have hosted my application on apache server on windows with an alias shortcut of apps
and the configuration works fine.我已经将我的应用程序托管在 windows 上的 apache 服务器上,并使用
apps
的别名快捷方式,并且配置工作正常。 I have also configured the .htaccess
file to reflect the alias and it works fine throughout the whole application.我还配置了
.htaccess
文件以反映别名,它在整个应用程序中都可以正常工作。 Here is my .htaccess file:这是我的 .htaccess 文件:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /apps/
# 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]
# Add /apps/ After The IP Address or Domain name
RewriteCond %{REQUEST_URI} !^/apps
RewriteRule ^(.*)$ /apps/$1 [L]
The problem arises when I use the named route Probation.index on the email view .当我在电子邮件视图上使用命名路由Probation.index时出现问题。 The email sends fine but when the recipient clicks on the button, it gives them a URL without the alias name.
电子邮件发送正常,但是当收件人单击按钮时,它会为他们提供一个没有别名的 URL。 I expect this:
http://example.com/apps/probation
but the result omits the apps
and shows http://example.com/probation
.我希望这样:
http://example.com/apps/probation
但结果省略了apps
并显示http://example.com/probation
。 Any suggestions are welcome!欢迎任何建议!
@Maksim Thank you. @马克西姆谢谢。 It solved the problem.
它解决了这个问题。 I wish you had written an answer rather than a comment so that I could approve it as an accepted answer and upvote you.
我希望你写了一个答案而不是评论,这样我就可以批准它作为可接受的答案并给你投票。 I modified my
.env
file and updated the APP_URL
to the appropriate prefix of my routes.我修改了
.env
文件,并更新了APP_URL
我的路线适当的前缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.