【问题标题】:How to do a redirect in Laravel for ads.txt如何在 Laravel 中为 ads.txt 进行重定向
【发布时间】:2019-07-26 13:13:11
【问题描述】:

Google 想要访问 ads.txt 文件,例如“example.com/ads.txt”,但在 Laravel 中我们需要将其重定向到“public”文件夹。

怎么做?

我尝试RedirectMatch 301 ^ads\.txt$ \/public\/ads\.txt,但它不起作用。

【问题讨论】:

    标签: .htaccess laravel-5 adsense


    【解决方案1】:

    将您的 ads.txt 文件放入文件夹:public(对于 Laravel),然后可以通过以下链接访问它:example.com/ads.txt。我在我的 laravel 网站上做了,它工作正常

    【讨论】:

      【解决方案2】:

      我已经通过以下方式解决了这个问题。

      在我的网络路由文件中:

      Route::get('/ads.txt', function () {
          $content = view('ads');
          return response($content, 200)
              ->header('content-Type', 'text');
      });
      

      我已将 ads.txt 文件重命名为 ads.blade.php

      或者只需将您的 ads.txt 文件添加到应用程序的公用文件夹中即可。

      【讨论】:

        【解决方案3】:

        您可以创建名称为ads.blade.php 的刀片文件并将ads.txt 中的所有文本放入此刀片,然后创建这样的路线:

        Route::get('/ads.txt',function(){
           return view('ads');
        });
        

        我在谷歌注册我的网站时尝试过

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-05-23
          • 2017-02-02
          • 2020-12-24
          • 2021-10-23
          • 2016-09-22
          • 2022-01-04
          • 2017-11-29
          相关资源
          最近更新 更多