0

I know this question has been asked many times in stack overflow, but I am not able to get the correct results.

I tried this link : htaccess redirect for Angular routes

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

so basically ,i am using https://github.com/angular-ui/ui-router for navigation in my app,

we have a url like this :

  1. www.xyz.com/products <= this url working fine, ( on hard refresh it is working fine )

  2. www.xyz.com/displayOrders/12 <= this url is not working when we do hard refresh from browser. WHY?

also my nested views are not working :

  1. www.xyz.com/message/notfication/12

what i wrote in .htaccess file is :

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]


  RewriteRule (.*) index.html [L]


</IfModule>

my base tag is this :

<base href="/"> and i also made html5mode as true in app.js

1 Answer 1

1

You should write .htaccess like this

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule (.*) /index.html [L]
</IfModule>

If your project in subdirectory example: www.xyz.com/shop/ You should write last rewriterule like this

RewriteRule (.*) /shop/index.html [L]

and base tag like this

<base href="/shop/">
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.