Angularjs htaccess html5mode rules

Angularjs  htaccess html5mode Rules


htaccess html5mode rules
htaccess html5mode rules

htaccess html5mode Rules Angularjs Create a site is very looking and linking root changed so create a htaccess file. more example htaccess

I have an angular application with several routes,
site.com/
site.com/page
site.com/page/3
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]

    RewriteRule ^(.*) /index.html [NC,L]
First you have to do is turn on HTML5 mode in your Angluar main or module's config page.

Copy and Paste for the following Code and add your code.
angular.module('main', []).config(['$locationProvider', function($locationProvider) {  
  ...
  $locationProvider.html5Mode(true);
  ...
});

htacces page redirect and 404 page not found and index page redirect 301, and 302 temporary redirect and  permanent  redirect code follows

  RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested pattern is file and file doesn't exist, send 404
RewriteCond %{REQUEST_URI} ^(\/[a-z_\-\s0-9\.]+)+\.[a-zA-Z]{2,4}$
RewriteRule ^ - [L,R=404]

# otherwise use history router
RewriteRule ^ /index.html

Angularjs htaccess html5mode rules Dev2Tricks 5 of 5
Angularjs  htaccess html5mode Rules htaccess html5mode rules htaccess html5mode Rules Angularjs Create a site is very looking an...

Share this

Related Posts

Previous
Next Post »