Jump to content

Single Page App htaccess config


microcipcip
 Share

Recommended Posts

I have a VueJS single page app with a router, how do I redirect all requestes to the index.php page? The processwire .htaccess file is quite big I am not sure how to change it. This is what is suggested in the router docs:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

 

Link to comment
Share on other sites

In short: You shouldn't. You won't want all requests to hit the index.html as it's going to prevent you from hitting processwire in any way (even ajax requests). I'd rather suggest letting your build steps transfrom the index.html into some file, which you can easily include as part of your templates and you're good to go and much more flexible.

The alternative would be serving processwire and the SPA unter totally separate domains / access points.

  • Like 3
Link to comment
Share on other sites

11 hours ago, LostKobrakai said:

In short: You shouldn't. You won't want all requests to hit the index.html as it's going to prevent you from hitting processwire in any way (even ajax requests). I'd rather suggest letting your build steps transfrom the index.html into some file, which you can easily include as part of your templates and you're good to go and much more flexible.

I don't understand how this would work. If I have a js route to http://mysite.com/about/ it returns a blank page when I refresh the page because that template doesn't exist in the ProcessWire FrontEnd, it's only in the JS route. ATM I am already outputting everything in the home.php PW template. All I am trying to do is redirect it to the home.php entry point so that the router will get the right url and load the right js page.

Link to comment
Share on other sites

8 hours ago, LostKobrakai said:

Just allow urlSegments on the home template, so it's a catch all for urls not existing in processwire itself.

The problem is that the js router is using the same URL of PW so the urls do exist, that's why when I refresh I see a blank page, because there's no php template associated with those pages.

Basically on PW I have a page like http://mysite.com/projects/ with a template projects (without php file) and the same url in the JS router.

The only possible solution I have in mind is move all pages to a container so that in this way I'll be able to allow the app to hit the home.php segment. Is there any other way? I need to rewrite several areas of the app if I change the url (for example the nav...).

Link to comment
Share on other sites

  1. If I browse to an existing page that does not have a php template, for example `http://www.mysite.com/projects/`, in the console I get "[HTTP/1.1 404 Page Not Found 94ms]". If I then create the template used for the 404 error page, it redirects to that template and never hits the home page.
  2. If I browser to a non-existing page, then it redirects correctly to the home.php page.
  3. If I create the template for the existing page, then it uses that page as template as usual, and not the home.php...

Do I need to use the home.php template as 404 error page? Still, it doesn't seem right that I'd get the [HTTP/1.1 404 Page Not Found 94ms] error message, expecially for SEO

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Hey @microcipcip. Did you manage to resolve this? I don't have an answer for you though - I have never used Vuejs. I searched for a simple 'how to use Vuejs' example but could not find one that did not require to install stuff via npm (or do stuff with gulp, or grunt or bower or similar; I don't use these tools [fortunately or unfortunately] - who comes up with such names anyway? :P). Anyway, would like to help test but don't have time to learn to use npm and similar :)

Link to comment
Share on other sites

I don't think vuejs is needed to test the problem here at all. The thing needed to work is urlSegments for the homepage, so that arbitrary url (besides the /api endpoint) still just return the homepage's content. 

Normally this should be working if there is just the homepage and an /api page, when urlSegments are enabled for the home template.

Link to comment
Share on other sites

On 12/12/2016 at 1:14 AM, microcipcip said:

If I browse to an existing page that does not have a php template, for example `http://www.mysite.com/projects/`, in the console I get "[HTTP/1.1 404 Page Not Found 94ms]". If I then create the template used for the 404 error page, it redirects to that template and never hits the home page.

Could you use the "Alternative Template Filename" option to assign the home.php file to all templates?

2017-01-09_214103.png

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...