Laravel - Root Url suffix and route prefix inconsistency - laravel

We have a test site with laravel 4, which is on a subfolder on the server. So it is on thedomain/sitename. This have caused big challenges with routing. The routes became wrong, like: thedomain/about instead of thedomain/oursite/about.
I added a Url root suffix'oursite' by using the Illuminate\Routing\UrlGenerator (following this suggestion).
All urls in the templates became correct, but they don't match anything in routes.php which still treats it without the suffix.
I tried adding a route prefix . Now the urls typed into the address bar worked. But all the urls in the templates became wrong, for instance thedomain/oursite/oursite/about.
So this seems inconsistent - why is the root Url suffix added to all the routes when they are echoed in the templates (like <a href="{{ route('about'); }} ) but they are interpreted without the suffix in routes.php!?
How can I get around that? I thought I was close to solving this. Or could I use route filter to redirect on every link?

Alternative solution: maybe use subdomain like sitename.thedomain.com instead of subfolder. If your server provider not support subdomains, change provider :P

Related

Passing more than one parameters in route messes up my view

I am a beginner to laravel. When I pass more than one parameter through the route my view gets messed up. For example when my route is {{URL/product}}. It is ok, but when try it the other way i.e {{URL/product/anything}}, the view is messed up.
[This is the correct view][1]
These are my routes :
(Working)
Route::get('/addproduct' , 'AdminController#add_product')->name('add_product');1
(not working)
Route::get('/add/product' , 'AdminController#add_product')->name('add_product');This one is not working
I haven't changed anything but my web.php file.
This is probably because of how you are linking to your assets. You are most likely using relative URLs. Try using one of the URL helpers to generate absolute URLs for you.
href="{{ asset('css/somefile.css') }}"
Laravel 7.x Docs - Helpers - URLs asset

Links in Laravel

I'm am just starting out in Laravel, been using codeIgniter for years. Very quick question as the Laravel documentation does not seem to address this. Do all links in your blade file have to have defined route in the routes files. In codeigniter it was generally /controller/function in your links but it seems to me in Laravel all links have to be defined in routes file...
No, they do not have to be defined.
There's nothing prohibiting you from using <a href='/whatever/you/want'> -- That said, it's generally better to use defined routes and reference them by name, that way, if you ever change the actual structures, the route('name'); will automatically resolve to the new structure.
You can use
{{ url('/what/you/want') }}
https://stackoverflow.com/a/42270157/4173464
Look at https://laravel.com/docs/7.x/urls too
You must define all your routes in Laravel.

How to Redirect urls after index.php in Laravel

We have a classified website developed in Laravel Framework. After analyzing the url structure I am getting the following issue:
Original Url: https://in.mysite.com/female-clothes/mycity
Duplicate Url: https://in.mysite.com/index.php/female-clothes/mycity
Every url is being duplicated as per the example given above.
Please let me know how to fix the above issue.
I think best option would be to 301 redirect Duplicate url to the Original url.
Please let me know the htaccess rule to fix the issue.
Do you know which version of laravel?
From what you've said this could be happening in the server (htaccess) or the application (laravel).
Laravel is able to handle url manipulation and redirection. The routing logic is usually found on the file called web.php (router.php for older version). It seems that the string 'index.php' is being inserted in the middle of your urls so look for it there.
If it's not happening in Laravel it could be in the htaccess, so look there as well.

Laravel 5.4 pretty url

Is that any ways to change the url such http://localhost:8080/myproject/advertisements to http://localhost:8080/myproject/admin/advertisements always for every URL. I hide the /public and move the .htaccess to root project.
Add a prefix to your route.
https://laravel.com/docs/5.4/routing#route-groups
Scroll down a bit to the Route Prefixes section

Use relative urls in Joomla menus

I have joomla site which is located in mydomain.com/somefolder/otherfolder/TheSite. I have created a rewrite rule to invisibly redirect all requests beginning with mydomain.com/TheSite to this url. It works fine.
My problem is that the urls that my menuitems point to are the old mydomain/somefolder/otherfolder/TheSite/stuff. If they were relative urls, it would work.
My question: How can I force joomla to use relative urls for the menuitems, or use the urls I explicitly specify?
Thanks in advance
Probably the easiest way to make Joomla produce only relative URLs is to edit the core method "_" of the JRoute class:
JRoute::_()
This is called by Joomla application and extensions to generate consistent URLs.
It is found in:
libraries/joomla/methods.php
Making Joomla spit out relative URLs probably isn't the best way to do it. Making the absolute URLs point correctly would.

Resources