Home Issue in 301 Redirect in Laravel 5.4
Reply: 0

Issue in 301 Redirect in Laravel 5.4

user2158
1#
user2158 Published in July 16, 2018, 2:46 am

I update the route of my category pages from /listing/category1 to /products/category1

Old Route:

Route::get('/listing/{slug}', 'ProductsController@listing');

New Route:

Route::get('/products/{slug}', 'ProductsController@listing');

Now I want to permanently redirect (301) my Old Routes to New Routes.

There are just 4-5 categories so I have added below code in .htaccess file in public folder to redirect all old URL's to New URL's manually with Redirect 301 script but it didn't work.

Redirect 301 /listing/category1 https://www.example.com/products/category1
Redirect 301 /listing/category2 https://www.example.com/products/category2

Please note website is having SSL certificate so links are starting with https.

There might be solution lying somewhere in Stack Overflow or some other website that I unable to found.

I tried adding below code in .htaccess file as well but of no use.

RewriteRule listing/category1 /products/category1 [R=301,L]
RewriteRule ^listing/([a-zA-Z0-9_-]+)$ products/category1

Complete code of .htaccess file is below:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteRule ^/?listing/([\w-]+)/?$ /products/$1 [L,NC,NE,R=301]

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

So Please help me telling How to permanently redirect Old Routes to New Routes in Laravel 5.4?

Thanks in advance!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313417 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO