Thursday 9 May 2019

2020 - laravel-vueJS-deployement Route handling - Change .htaccess file so some routes are handled by vue-router and some are handled by laravel



// Changes to laravel default .htaccess file

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

    RewriteEngine On

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

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


    # When domain is accessed, index.html page is autmotically served because of apache2 default DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm     ( /etc/apache2/mods-enabled/dir.conf)
    # If (url contains route_1, or route_2, and if file not found, we let vue-router to serve) 
    RewriteCond %{REQUEST_URI} ^/<route_1>[NC,OR]
   <....MANY MORE VUE ROUTES you wish to add in future>
    RewriteCond %{REQUEST_URI} ^/<route_2>[NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /index.html [L]

    # IF !(url contains route_1, or route_2, and if file not found, we let laravel-router to serve) 
    RewriteCond %{REQUEST_URI} !^/<route_1>[NC]
    RewriteCond %{REQUEST_URI} !^/<route_2>[NC]
    # make sure we haven't already rewritten this URI
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # Rewrite everything else to laravel router in index.php
    RewriteRule ^ index.php [L]

</IfModule>





https://stackoverflow.com/questions/11906060/is-there-a-way-to-if-else-a-rewrite-in-apache-htaccess
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
https://www.adayinthelifeof.nl/2012/01/21/apaches-fallbackresource-your-new-htaccess-command/
https://stackoverflow.com/questions/7873634/why-does-index-html-have-priority-over-index-php

No comments:

Post a Comment