0

I'm struggling with .htaccess a little.

I have routes in routes.php like for:

/category/{categorySlug}
/product/{productSlug}
/tag/{tagSlug}

I need to use even nicer urls that looks like:

some-category.c.html --> /category/{categorySlug}
iphone-7s.p.html --> /product/{productSlug}
samsung-galaxy.t.html --> /tag/{tagSlug}

It should not use redirect, only identify url pattern ant continue further to routing with remade url. It should stay as it is on browser.

I have tried something like this with various variations with RewriteRule ^(.*).c.html$ /category/$1 [NC] but no success (all other config is default that comes with fresh Laravel 5.5 install):

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

    RewriteEngine On

    # Tried various flags...
    RewriteRule ^(.*).c.html$ /category/$1 [NC]

    # 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>

Thanks! :)

1
  • You want to use routes like this {categorySlug}.c.html instead of /category/{categorySlug}? Commented Oct 26, 2017 at 14:57

1 Answer 1

0

I'm not sure that trying to customize .htaccess is the best way.

If you want to have a route like this localhost/some-category.c.html instead of localhost/category/some-category.

You should try something like that :

Route::get('{categorySlug}.c.html','Controller@method');
Route::get('{productSlug}.p.html','Controller@method');
Route::get('{tagSlug}.t.html','Controller@method');

If you still want to edit the .htaccess, you can give a look to those links :
- How to change url? htaccess
- url rewriting using htaccess for category & product in php

Sign up to request clarification or add additional context in comments.

1 Comment

Yep. In older Laravel it wasn't possible to use dots in url route. Now it seems that they've implemented that. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.