jeudi 22 février 2018

Redirecting error from/back to an outer URL

I have an on production application build with php and Laravel 5. When i tried to add Internationalization to the website, i added routes to change lang /en, /fr and /es to handle lang switch in the app and that makes google and only google index my website to those roots.

my web.php file:

<?php
 Route::get('/', 'WelcomeController@index')->name('welcome');
 Route::name('language')->get('/{lang}', 'WelcomeController@language');
 /*...other routes...*/
?>

The problem that i develop those roots to change lang. and redirect web client back to the page he came from! in the case he came from a google search page my app redirect him back to google.

class WelcomeController extends Controller
{
  /*...other functions*/
  public function language(String $locale)
  {
    $locale = in_array($locale, config('app.locales')) ? $locale : config('app.fallback_locale');
    if (!session('locale')) {
      session(['locale' => $locale]);
      return redirect()->action('WelcomeController@index');
    }
    session(['locale' => $locale]);
    return back();
  }
  /*...*/
}

I want to check if he is coming from outside and redirect him to / by checking if there is a session but it work the same (because there is session opened in other website too). Is there is regular fix to this issues in laravel or can any one suggest an idea to solve that.


OR

Should i try to make google refer to / and is that possible using sitemap.xml where i don't declare the root but only the 3 alternate.

<urlset ...>
  <url>
    <loc>https://example.com/en/</loc>
  ...
  </url>
  <url>
    <loc>https://example.com/fr/</loc>
  ...
  </url>
  <url>
    <loc>https://example.com/es/</loc>
  ...
  </url>
</urlset>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire