Removing hashUrl with rewriting example in angular js

Removing hashUrl with rewriting example in angular js

Today, We want to share with you Removing hashUrl with rewriting example in angular js.
In this post we will show you Removing hashUrl with rewriting example in angular js, hear for Removing hashUrl with rewriting example in angular js we will give you demo and example for implement.
In this post, we will learn about Removing hashUrl with rewriting example in angular js with an example.

I am Posting Url rewriting example with full source code in angular js with complete source code to achieve it . If you are angularjs beginner with angular 2 then you might faced some problems issues with hash(#) sign in angular.For in this POSTAngular SEO : Removing the hash and re-writing the .htaccess file.

READ :  Vue js Event Handling custom components and methods

htaccess redirect for Angular routes

The Google does have a include page url way of indexing AJAX call to the applications and your web app’s AngularJS app can be crawled based to the resolved, indexed and will appear created some data in search results check to just like any other more website.

Angular SEO : Removing the hash and re-writing the .htaccess file.

.config(function ($routeProvider, $locationProvider)
  {
    $routeProvider
    .when('/', { templateUrl: 'views/main.html', controller: 'MainController' })
    .when('/about', { templateUrl: 'views/about.html', controller: 'AboutController' })
    .when('/careerlinks', { templateUrl: 'views/careerlinks.html', controller: 'CareerLinksController' })
    .otherwise({ redirectTo: '/' });

    //You'll need this to remove the hash.
    $locationProvider.html5Mode(true);
    }
    );

Removing the hash and re-writing the .htaccess file. | Angular SEO

base href="/"
RewriteEngine On
RewriteBase / RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

In this post,URL REWRITING EXAMPLE IN ANGULAR JS is a complete Url form page rewriting example in angular js or more javascript frameworks, where i have used htaccess and Route provider for simple steps to make pretty url in angularjs

READ :  Angular HTTP POST method request & response

RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]

    RewriteRule ^(.*) /index.html [NC,L]

rewrite rules for apache 2 to use with angular js

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# simple solution of the if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/api

# new rules define to otherwise forward it to index.html 
RewriteRule ^.*$ - [NC,L]
RewriteRule ^app/. /app/index.html [NC,L]

When a search engine(Like as a Google) crawler visits your app or web-applications and sees the data of simple it will add an ?_escaped_fragment_= tag to your URL in angularjs.

Full Source code of the Url rewriting example in angular js



<title>Url rewriting example in angular js - SEO Friendly ANGULAR APP </title>


<a href="http://angular.min.js">http://angular.min.js</a>
  <a href="http://angular-route.js">http://angular-route.js</a>


<h1>URL REWRITING EXAMPLE IN ANGULAR JS</h1>
<p><a href="./">PHP</a>   <a href="laravel">Laravel</a>   <a href="services">Services</a>   </p>
 <div></div>


var MyApp = angular.module('MyApp', ["ngRoute"]);
MyApp.config(['$routeProvider', '$locationProvider', function ($routeProvider,$locationProvider,$http){
	$locationProvider.hashPrefix('!');	  	
	$locationProvider.html5Mode(true);
	$routeProvider

	.when('/',
	{templateUrl:'php.html'
	})
	.when('/laravel',
	{templateUrl:'laravel.html'
	})
	.when('/services',
	{templateUrl:'services.html'
	})
	.when('/not-found',
	{templateUrl:'404.html'
	})
 
	.otherwise({
	  redirectTo:'/not-found'
	});
 }]);


We hope you get an idea about Removing hashUrl with rewriting example in angular js
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

READ :  Simple Angular Form Validation PHP MySQLi

We hope This Post can help you…….Good Luck!.

https://pakainfo.com/

Leave a Reply

Your email address will not be published. Required fields are marked *