rewrite rule for deep linking and location

3,609 views
Skip to first unread message

AJ Mercer

unread,
Jun 26, 2012, 8:30:29 PM6/26/12
to ang...@googlegroups.com
Does anyone have the rewrite rules for apache that enable angular to go directly to a deep-linking URL?

My App works when staring from index.html
using code from script.js on

AJ Mercer

unread,
Jun 28, 2012, 5:03:33 AM6/28/12
to ang...@googlegroups.com

Maybe I am asking the wrong question.

What needs to be done in order to be able to browse directly to a deep link?

Marcello Nuccio

unread,
Jun 28, 2012, 5:21:28 AM6/28/12
to ang...@googlegroups.com
If I understand correctly your question, you simply build the link to the resource:

    <a ng-href="#/foo?id={{id}}">Go to foo {{id}}</a>

You need ng-href only if the href value contains bindings.

AJ Mercer

unread,
Jun 28, 2012, 8:28:07 AM6/28/12
to ang...@googlegroups.com
My app has links to /about and /contact 
that work within the application

I have just worked out that if I put this in the address bar
/#/contact
it gets redirected to /contact and displays the corect contents :-)


From previous posts with 0.9
I was told a rewrite rule is required on the web server to map to the hash (bang) URL

This is what I have in my .htaccess at the moment - not working

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

RewriteRule ^/(.*)       /index\.html/#/$1 [L]
</IfModule>

# END angularJS




--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/I0W-TvpNfGUJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

AJ Mercer

unread,
Jun 29, 2012, 1:07:45 AM6/29/12
to ang...@googlegroups.com
finally figured it out

for those that are using Apache Web Server - here is my .htaccess

# BEGIN angularJS
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)       /index.html/#/$1 
</IfModule>
# END angularJS

stephen....@gmail.com

unread,
Aug 23, 2012, 7:50:03 PM8/23/12
to ang...@googlegroups.com
There is what I would say is a better way to handle this, so that the URL doesn't get "re-written", but instead the request just channels to the correct place. Essentially all you want is every request you make to go to index.html, but NOT to update the URL in the browser. This can be done with a reverse proxy.

You can use mod_jk to do this, although I prefer to use mod_proxy. Your URL will never have a /#/ in it, and it will never 'flash' from 1 URL to another when loading, instead it will always show the URL that was entered in the address, but only ever hit index.html, and AngularJS will automatically handle which part of the app to show. I've not tested this yet, but this is how I plan to implement it in the near future to avoid having to support hash.

ysan...@gmail.com

unread,
Sep 24, 2012, 11:00:53 AM9/24/12
to ang...@googlegroups.com, stephen....@gmail.com
Did you or anyone else do something like this yet? I am very interested :)

Qaiser Abbas

unread,
May 11, 2013, 3:32:32 AM5/11/13
to ang...@googlegroups.com
The solution given in this post didn't work for me (in Firefox), but this rule works:

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

Pan Stav

unread,
May 11, 2013, 5:51:11 PM5/11/13
to ang...@googlegroups.com
sorry for uping old discussion

What if my app is not the main dir but something like mydomain/testdir/index.html
and i want to have angular dealing with all partial direct urls and 404s

i was thinking of making a rule for all of the possible urls, when my websiteapp was about the size of 5 patials, 
but then i figured it was more like 500, so surely there's a better solution
Reply all
Reply to author
Forward
0 new messages