mercredi 19 octobre 2016

Cant internal rewrite pretty url with laravel and htaccess

I'm having a problem doing internal rewrites with apache/htaccess and Laravel 5.1. The scenario is quite simple, I have some routes working on my app that needs to be rewritten to a more human/SEO/Customer friendly URL, my initial approach was simply rewrite them in htaccess as I did so many times.

However the, problem rises when I try to do it and it does not work at all, for example, if I have the url http://ift.tt/2ekeStU and I want to rewritte to http://ift.tt/2dqbTtX

Normally i would do:

RewriteRule ^dummy-dummy-dummy-id.html /myroute/$4

However when I follow this pattern with this laravel project I got a 404 error, i have been doing tests for some days and it does not matter what to do, it will always give you a 404 unless using the flag [R] wich redirects de request externally instead of the internal behaivor i need.

I have been using a dd() in the AppServiceProvider to see the details of the request the framework is getting and the URI it gets is allwas the friendly one (so the internal redirect does not reach the index.php) I have been looking at the mod_rewrite debug logs and looks like it is working fine matching the friendly url and doing and internal rewrite, but it never reaches the framework :(

this is the full htaccess:

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

    php_value upload_max_filesize 30M
    php_value post_max_size 6M

    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} !^local\.
    RewriteCond %{HTTP_HOST} !^beta\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

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

    RewriteRule ^dummy-dummy-dummy-id.html /myroute/$4

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

NOTE: I know that I can implement the friendly routes straight in the routes file of laravel, but I don't understand why this is not working so I would like to find out.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire