Comments (5)
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.
Hey @monsieurbab,
Is there any reason why you would like a trailing slash only for the home routes?
from laravel-multilingual-routes.
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.
@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.
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)
- Default route is not defined HOT 2
- Possible to use subdomain/domain instead of /en/home HOT 3
- Customize 404 and 500 error pages HOT 2
- Redirections HOT 4
- Prefixed route results in 404 HOT 13
- How to initiate this package? HOT 6
- Another Question - localized_route HOT 7
- How use multilingual for /{slug} HOT 2
- On 404 page, current_route with fallback throws an error HOT 2
- locale() method never return "en" for default (for fallback lang) route HOT 1
- Maximum function nesting level of '256' reached, aborting! HOT 2
- Binding routes not working HOT 1
- Error when Route not defined for this locale HOT 4
- InvalidArgumentException Attribute [multilingual] does not exist. HOT 2
- Not detecting 'as' in routes HOT 1
- Prefixed routes are malformed after route:cache command HOT 1
- current_route compatibility with spatie/laravel-translatable and spatie/laravel-sluggable? HOT 5
- How to deal with Route::resource()? HOT 1
- Prefixed routes do not localize the URI HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-multilingual-routes.