2

I'm trying something I thought would be fairly simple: namely, to redirect domain.com/dashboard/ to another (different) application than my main domain, (which is a wordpress install, but that's fairly irrelevant I think).

So when visiting domain.com/dashboard/anywhere, this second application should act as if /dashboard/ was the route of the domain, and process all urls etc as normal.

What I have tried so far either just causes a redirect loop, doesn't route at all or gives a 500 error.

Here's an example of my nginx location for this so far:

location ~ ^/dashboard/
{
   alias /srv/www/htdocs/fork/; // this is the second application I want to access

   rewrite "^(/.*)$"      http://domain.com/$1 permanent;

   index index.php index.html;

   include /etc/nginx/fastcgi_params;

   fastcgi_pass  127.0.0.1:9000;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

   break;
}

I've tried switching from alias to root also, but to no avail. And I'm not really sure what to try next.

Does anyone have any idea about what could be causing the redirect? (Essentially causing a loop of domain.com/dashboard/dashboard/dashboard (etc).

Update

Okay, so following Mark's advice below, I've moved the location block above any wordpress rules, and I've commented out some code. Progress has been made in that now a request to domain.com/dashboard/ will access the right application, but it's now looking in that application for a dashboard folder.

Here's the current code:

location ~ ^/dashboard(/)(.*)$
{
   root /srv/www/htdocs/fork/;

   break;
}

and the current error in the logs is "/srv/www/htdocs/fork/dashboard/index.php" is not found (what I'm after is it accessing /srv/www/htdocs/fork/index.php.

2 Answers 2

0

The first time that /dashboard/foo gets hit, the processing gets down to the rewrite line, where it stops processing and redirects back to /dashboard on the same domain, creating a loop.

It may well be relevant that your other app is a Wordpress installation, because Wordpress includes it's own rewrite directives, which basically say that if any URL does not map to a a physical file or directory, than pass it to Wordpress. So, it's important that this bit of configuration appear before the Wordpress rewrite rules.

If I understand the situation correctly and both apps are on the same domain, you don't need the rewrite directive here. The alias directive should be sufficient to serve the /dashboard address from a different location.

7
  • Hey @mark yeh, you're correct both are on the same domain, I just want /dashboard/ to go to a new application. I've moved the location block above the wordpress rules and taken out the rewrite, but I'm still getting the redirect loop to dashboard/dashboard/dashboard
    – josh
    Aug 6, 2013 at 14:08
  • try commenting out the whole location block and see if you still get the error. If you do, the problem is elsewhere. If you've narrowed down to this location block for certain. Try commenting out particular lines until the behavior changes. Aug 6, 2013 at 14:54
  • I've made sure the fault definitely lies within the location block, and updated above. There's some progress (it's getting to the right application), but it's checking in the wrong place. Please see above (and thanks for your help so far!)
    – josh
    Aug 6, 2013 at 15:08
  • Based on your description, it sounds like alias, not the root directive is what you want. Aug 6, 2013 at 15:35
  • Added that, and now it's getting a redirect of dashboard/index.php/index.php/index.php etc (and yes, there is an index.php).
    – josh
    Aug 6, 2013 at 15:44
0

Try alias instead:

location /dashboard {
  # you don't need regexps here, naming location will use hash lookup which is much faster
  alias /srv/www/htdocs/fork/;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .