Using Yii2 as the back end for a single page application

Hi

I have a single page app (angular) which I need to be indexable by search engines using the advised ?_escaped_fragment= which replaces hash bangs.

In my routing scheme I map page/about to a generic action on my page controller rather than use something like page/view/1

For the single page app the equivalent URL would be /#!/page/about

Ive been trying to do this on Yii 1.15 to no avail see my post

http://www.yiiframework.com/forum/index.php/topic/61348-routing/page__fromsearch__1

A solution would be great for 1.15 obviously but I am now learning Yii2 and it would be great to know how to solve this sooner rather than later!

I’ve read its recommended to set up the rest api as a separate application which is fine but it would be great to know how to route URLs containing the escaped fragment correctly

Hi,

Still searching for some help here - think it’s really important to be able to use Yii(2) as the back end for a single page web appplication using (eg) Angular or Ember.

To make the spa crawlable without relying on push state, I need to include the ?_escaped_fragment in the url. I couldn’t get this to work on Yii1 and still can’t on Yii2. I need to have pretty urls and remove the scriptName in the urlManager but if you do this it doesnt work at all - no routes can be reached.

Have tried using




'routeParam' => '_escaped_fragment',



in my urlManager but that obviously only works with pretty urls turned off

  1. How should URLs look like? Any examples?

  2. What are your URL rules currently?

  3. Which controller actions are to be executed?

Hi Sam, many thanks for getting back. I’m solving it by writing a custom Url rule, which extracts the ?_escaped_fragment from the request, and then the route and action turning

?_escaped_fragment=site/contact into site/contact

Seems to work!