Open ahmtcn34 opened 6 months ago
Add a router before pattern definition then redirect to url you want.
$webRouter->router->get('/', function () { header("location: https://example.com/tr"); });
İstediğim tam olarak bu değil. Kullanıcının seçtiği dili alıp urlyi ona göre dinamik yönlendirmek.
Bunun için eklenen custom parametre için default bir değer eklemek gerekiyor ama şu an direkt olarak paket üzerinde bu tarz bir özellik yok. Tavsiyem middleware ile handle edip, ilgili default endpoint'e yönlendirmek olur.
@ahmtcn34 dostum,
domain.com/ bu şekilde girilince yani herhangi bir dil kısaltması yoksa urlde otomatik olarak domain.com/tr adresine yönlendirmek istiyorum
bu sorunun cevabı idi.
Middleware ile aşağıdaki şekilde handle edebilirsin dostum.
`<?php
namespace App\Middlewares;
use Symfony\Component\HttpFoundation\Request;
class HandleLocale { public function handle(Request $request) { $pathInfo = substr($request->getPathInfo(), 1); $routerIndexes = array_filter(explode('/', $pathInfo)); $locale = $routerIndexes[0]; header("location: https://expamle.com/" . $locale); } } `
Middleware ile aşağıdaki şekilde handle edebilirsin dostum.
`<?php
namespace App\Middlewares;
use Symfony\Component\HttpFoundation\Request;
class HandleLocale { public function handle(Request $request) { $pathInfo = substr($request->getPathInfo(), 1); $routerIndexes = array_filter(explode('/', $pathInfo)); $locale = $routerIndexes[0]; header("location: https://expamle.com/" . $locale); } } `
Yardımınız için teşekkür ederim. Aşağıdaki gibi yaptım şu an sorunsuz çalışıyor. İhtiyacı olan arkadaşlar olursa diye paylaşmak istedim.
Url yapısını aşağıdaki resimde göründüğü gibi kurguladım. Normal şekilde dil kısaltması kullanarak sayfalara ulaşabiliyorum. Örnek domain.com/tr. Fakat şöyle bir şey yapmak istiyorum. domain.com/ bu şekilde girilince yani herhangi bir dil kısaltması yoksa urlde otomatik olarak domain.com/tr adresine yönlendirmek istiyorum. Bu yapmak istediğim şey mümkün mü? Kullanım olarak bulamadım.