[英]Redirect url in laravel
My website Was run with laravel But its address is displayed in Google in this way👇👇我的网站是用laravel运行的 但是它的地址在谷歌中是这样显示的👇👇
Https://examle.com/public/ https://examle.com/public/
How i can delete (public) from my url?我如何从我的网址中删除(公开)?
This is my .htaccess codes:👇这是我的 .htaccess 代码:👇
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Hi and welcome on StackOverflow.嗨,欢迎来到 StackOverflow。
To remove /public
from the url of your app you will need to edit the .htaccess
you provided and put it in the main folder of your Laravel project (ie: where lies .env
, composer.json
, etc.), assuming you placed all the code of your Laravel app in the main domain directory of your Hosting Service.要从应用程序的 url 中删除
/public
,您需要编辑您提供的.htaccess
并将其放在 Laravel 项目的主文件夹中(即: .env
、 composer.json
等所在的.env
),假设您放置了您的 Laravel 应用程序的所有代码都在您的托管服务的主域目录中。 The new .htaccess
will look like this:新的
.htaccess
将如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
# All other C-Panel related stuff
This will internally map all of your urls to /public
directory hiding /public
in browser.这将在内部将您的所有 url 映射到
/public
目录,在浏览器中隐藏/public
。
Remember to not edit or delete the .htaccess
file inside the public
folder unless strictly necessary记得不要编辑或删除
.htaccess
内部文件public
文件夹,除非绝对必要
You can try the code between <IfModule mod_rewrite.c>
and </IfModule>
with this online tool您可以使用此在线工具尝试
<IfModule mod_rewrite.c>
和</IfModule>
之间的代码
I also suggest to install a local Apache Server (like XAMPP ), try to setup a Virtual Host and play a bit with .htaccess
file to understand how to properly set up your Laravel Project in production.我还建议安装一个本地 Apache 服务器(如XAMPP ),尝试设置一个虚拟主机并使用
.htaccess
文件来了解如何在生产中正确设置你的 Laravel 项目。
Here's a guide on how to create a Virtual Host on XAMPP. 这是有关如何在 XAMPP 上创建虚拟主机的指南。 It may be useful as a starting point to start creating one on your own.
作为开始自己创建一个的起点可能很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.