1

I've got an Angular app using html5mode, but it's currently sitting within a sub-folder of a site: http://somesite.com/za/

So I've managed to rewrite the url to direct to my assets folder correctly, but I'm still getting 404s when I hit refresh or navigate directly to a page.


So this works: http://somesite.com/za/assets/js/bundle.js

This doesn't work, 404: http://somesite.com/za/home


.htaccess

RewriteEngine On
#This apparently creates a redirect loop for angular
RewriteRule ^(.*)/$ /$1 [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(za/.*) /za/index.html [NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:[^/]*/)*([^/.]+\.(?:jpe?g|gif|bmp|png||css|js))$ za/assets/$1 [R=301,L,NC]

AddType image/svg+xml svg svgz
AddEncoding gzip svgz

So where is the rewrite failing to redirect to index.html when I hit or refresh a page?

2
  • I don't think you need a rewrite rule you only need to set the base tag in the head of your HTML: <base href="/za/" /> Commented Dec 8, 2015 at 7:52
  • @Michelem, base tag is already set: <base href="/za/"> Commented Dec 8, 2015 at 7:59

1 Answer 1

4

Solved it with a more elegant rewrite rule:

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

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

However, this does give read access to other files and directories, so it can have security issues.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.