skip to Main Content

the default link structure in the project I am working on is as follows;

https://abcsite.com/abcsite/about-us

but the path in between is not used, how can I remove it?

one more example, the link structure on the solutions page is as follows;

https://abcsite.com/abcsite/solutions-1/what-is-abscsite-6

/abcsite, /solutions-1, this paths unused.

I want to remove these paths and the id numbers at the end.

I looked at the route and middleware structure but I couldn’t reach a conclusion

2

Answers


  1. Chosen as BEST ANSWER

    this method does not work in my project, there is a route structure in the project;

    Route::get(Session::get('locale').'/'.trans('site.abc').'/{link}/{link2}', [SitePageController::class, 'subDetail']);
    

    The class structure is also as follows;

    public function subDetail(Request $request, $toplink, $link)
    {
        $page           = Pagedescription::whereLink($link)->first();
        $record         = Pages::whereId($page->page_id)->first();
    
        $topPage        = Pagedescription::whereLink($toplink)->first();
        $topRecord      = Pages::whereId($topPage->page_id)->first();
    
        if ($record->parent_id == 1) {
            if ($record->id == 39) {
                return View('site.pages.forwho', compact('record'));
            } else {
                return View('site.pages.discover', compact('record'));
            }
        } elseif ($topRecord->id == 2) {
            $customerComments = Pages::whereId(29)->first();
            return View('site.pages.solutions', compact('record', 'customerComments'));
        } elseif ($topRecord->id == 3) {
            return View('site.pages.features', compact('record'));
        } elseif ($topRecord->id == 33) {
            return View('site.pages.blogDetail', compact('record'));
        } elseif ($record->id == 86) {
            return View('site.pages.helpCenter', compact('record'));
        } elseif ($record->parent_id == 206) {
            return View('site.pages.expert', compact('record'));
        } else {
            $otherPages = Pages::whereParentId($record->parent_id)->orderBy('ordernum', 'ASC')->get();
            return View('site.pages.blankPage', compact('record', 'otherPages'));
        }
    }
    

  2. To achieve the desired clean URL structure and remove the unused paths and ID numbers, you can consider the following steps:

    Update Routes:
    Review your routes and ensure they match the desired URL structure. You may want to simplify the structure and remove unnecessary segments.

    Example:

    Route::get('/about-us', 'AboutUsController@index')->name('about-us');
    Route::get('/solutions', 'SolutionsController@index')->name('solutions');
    Route::get('/solutions/what-is-abcsite', 'SolutionsController@whatIsAbcSite')->name('solutions.what-is-abcsite');
    

    Controller Actions:
    Update your controller actions to reflect the simplified URLs. Remove unnecessary path segments and IDs.

    Example:

    class AboutUsController extends Controller
    {
        public function index()
        {
            return view('about-us');
        }
    }
    
    class SolutionsController extends Controller
    {
        public function index()
        {
            return view('solutions.index');
        }
    
        public function whatIsAbcSite()
        {
            return view('solutions.what-is-abcsite');
        }
    }
    

    Update Links in Views:
    Update your links in Blade views to match the simplified structure.

    Example:

    <!-- Link to About Us -->
    <a href="{{ route('about-us') }}">About Us</a>
    
    <!-- Link to Solutions -->
    <a href="{{ route('solutions') }}">Solutions</a>
    
    <!-- Link to What Is ABCSite in Solutions -->
    <a href="{{ route('solutions.what-is-abcsite') }}">What Is ABCSite</a>
    

    Clear Route Cache:
    After making changes to routes, clear the route cache to apply the updates:

    php artisan route:clear
    

    Check for Redirections:
    If the old URLs are still resulting in 404 errors, check if there are any redirections in place that might be conflicting with the new structure.

    Check .htaccess or Server Configuration:
    If you are using Apache, ensure your .htaccess file is configured correctly. If you are using Nginx or another server, make sure the server configuration allows the desired URL structure.

    After making these changes, you should have a cleaner URL structure without unused path segments and ID numbers. Remember to test thoroughly to ensure all links and routes are working as expected.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search