Url Shortener in Laravel


Url Shortener in Laravel

我有一个问题,如何使url缩短?例如,我有这个url "localhost/public/action/1"变成这样"/action/1"

我已经看到如何使url缩短从杰弗里的方式,但我想使url缩短不使用数据库,但得到url作为缩短url的参数。提前感谢

您可以通过将文档根目录直接指向public文件夹来缩短url。在nginx中,你可以这样配置它:

server {
   listen 80;
   server_name localhost;
   root /path/www/laravel_app/public; #this part
   ...
}

或在Apache中:

<VirtualHost *:80>
DocumentRoot /path/www/laravel_app/public
ServerName localhost
# Other directives here
</VirtualHost>

这将使您避免在URL中使用public。如果你想让它更短,在你的hosts文件中添加这样的内容:

127.0.0.1 dev

然后将server_name更改为dev,这将使URL如下:

dev/action/1

编辑:你是在说让URL http://path/to/a/very/long/exhausting/locationhttp://shorty/1234吗?

你不需要网页缩短器。如果你把这个设置为live, Laravel将存在于你的"公共"文件夹中,这将是你的域名。

所以你的链接会自动变成www.example.com/action/1

由于您的本地服务器设置,您只能看到localhost/public。根据您运行的web服务器,您可以更改此设置,但它不会影响您的编码或部署。