Charles Gillespie
Charles Gillespie

Reputation: 3

html5mode angularjs ui-router .htaccess re write rules

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

Upvotes: 0

Views: 945

Answers (1)

Meta Sanjaya
Meta Sanjaya

Reputation: 11

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/">

Upvotes: 1

Related Questions