Garsallah mohamed Garsallah mohamed - 5 months ago 39
AngularJS Question

.htaccess redirection for SEO configuration

I have an angularJs based portfolio, Google crawler offer a URI tool for similar platforms. replaces the

#!
by
?_escaped_fragment_=
which you can use server redirection to changed the directory to serve static files.

I don't use
#!
so the
?_escaped_fragment_=
will be inserted at the end. What I like to do is to make this pattern:

www.mywebsite.com/?_escaped_fragment_=
www.mywebsite.com/page/?_escaped_fragment_=
www.mywebsite.com/page/5?_escaped_fragment_=


Redirects to

www.mywebsite.com/snapshot
www.mywebsite.com/snapshot/page/
www.mywebsite.com/snapshot/page/5


This is the .htaccess file that I used:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^$ /snapshot/
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html


The problem is that It only works for the base URL (index.html).
Is there a thing that I am missing?
Thank you.

Answer

You have to use the escaped fragment like this:

http://yourangularwebsite.com/?_escaped_fragment_=/page/5

Then redirect it in your .htaccess:

RewriteCond %{QUERY_STRING} _escaped_fragment_=/([^&]*)
RewriteRule ^$ /snapshot/%1 [R,L]

This should redirect you to http://yourangularwebsite.com/snapshot/page/5?_escaped_fragment_=/page/5