0

I'm trying to use AngularJs with html5mode enabled, and to be able to use it i need to enable a rewrite i need an .htaccess to point to the folder.

When going to the root index, there is no problem, everything works fine. But when i try to redirect to a subfolder where there is another section, i keep getting errors. For example, i have an admin section to publish news, etc.. So to access this portion of the app i need to go to a subfolder called /adm like this www.site.com/adm and this is where the errors starts.

This is my .htaccess file

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

And this is the errors I'm getting:

Uncaught SyntaxError: Unexpected token <

When looking further, i see this is point to the index on the root. I know it has something to do with the .htaccess file, but i don't how to create a rule to identify if it's a root folder or sub folder and create the proper rewrite rule.

4
  • did you add a base href to your html file? docs.angularjs.org/guide/$location#relative-links Commented Apr 12, 2016 at 23:59
  • @Ronnie Yes. the base is /adm also tried /adm/ Commented Apr 13, 2016 at 0:04
  • What is supposed to happen inside /adm ? Should the rewrite work inside that folder? If so, what is the expected result? Yes, right now everything that is not existing file or folder gets rewritten into index.html in root Commented Apr 13, 2016 at 7:46
  • @poncha it's a whole new section. For example, i have the web site on the root, and when accessing the /adm it's a new section only for admins, to manage the website. So this subfolder will have it's own index, folders, views, etc.. The rewrite needs to happen on this directory as well (i think) because it also need to have html5mode enabled in order to remove the # from the url. Commented Apr 13, 2016 at 11:29

1 Answer 1

1

Try this:

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

What this does is rewrite everything inside /adm/ to /adm/index.html and everything else to /index.html

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.