Giter Site home page Giter Site logo

Comments (5)

chinleung avatar chinleung commented on May 20, 2024 1

No, I only need it for the Home route of each language.

By default Laravel has this rule in the .htaccess:

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

If you can't add the option of trailing slash for some routes only, then I think I'll put a rule in the .htaccess for our Home routes. That will be simpler ;)

Thanks for your help!

Oh I see. I use nginx which doesn't use the .htaccess, that's why it's working for me! Wouldn't that rule remove the trailing slash even if you register the route with a trailing slash though? 🤔


I found a workaround to register the home routes with a trailing slash:

Route::multilingual('home', '...');

And then in all your translation files resources/lang/{locale}/routes.php, you can add the following:

return [
    'home' => '/',
];

This will give you the following routes:

+------------------------+--------------+
| URI                    | Name         |
+------------------------+--------------+
|                        | en.home      |
| fr/                    | fr.home      |
+------------------------+--------------+

However, when you use the route helper, it will remove the trailing slash automatically:

localized_route('home', [], 'fr'); // https://demo.test/fr
route('fr.home'); // https://demo.test/fr

I think it'd be best if you alter the rules in your .htaccess to add the trailing slashes for your home route to achieve what you'd like!

Have a nice day. 😄

from laravel-multilingual-routes.

chinleung avatar chinleung commented on May 20, 2024

Hey @monsieurbab,

Is there any reason why you would like a trailing slash only for the home routes?

from laravel-multilingual-routes.

monsieurbab avatar monsieurbab commented on May 20, 2024

Thank you for the quick reply!

There is no particular technical reason. This is a "URL style" that we use on our current website and we would like to keep it. None of our URLs do not contain a slash at the end except for Home which acts as the starting point of a "Language Folder" if you imagine it like that.

Do you think it's possible that you add the option to the package or do you think it would be better to manage this in our .htaccess file?

from laravel-multilingual-routes.

chinleung avatar chinleung commented on May 20, 2024

@monsieurbab What about the other routes though? Do they have a trailing slash?

If I'm not mistaken, Laravel supports the trailing slash by default.

So if your registered route is /fr, the /fr/ would work as well.

I could add an option to add a trailing slash but it would be for all routes managed by the package, not only the home url.

from laravel-multilingual-routes.

monsieurbab avatar monsieurbab commented on May 20, 2024

No, I only need it for the Home route of each language.

By default Laravel has this rule in the .htaccess:

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

If you can't add the option of trailing slash for some routes only, then I think I'll put a rule in the .htaccess for our Home routes. That will be simpler ;)

Thanks for your help!

from laravel-multilingual-routes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.