0

Hi I have implemented a Rails app with nginx and deployed on Amazon Web Services.

I have written different rules for 301 redirection.

On of them is the following in nginx.conf:

rewrite (?i)^/abc/HomePage.aspx(.*) /#!/Home$1 permanent;

However I am able to redirect to home page but am having trailing characters in the URL, which can be dynamic.

For example, if the URL (old site) is http://x3.com/abc/HomePage.aspx?_=72HNtUhJkGN5yXngjof0jLZ1yv7ykDfnNwsiYcgx9xqpVoLH0UvC5nneQnFfwTQnnC5w4nYtXuBc7DIA16BxkA==

it is landing on http://www.x3.com/#!/Home?_=72HNtUhJkGN5yXngjof0jLZ1yv7ykDfnNwsiYcgx9xqpVoLH0UvC5nneQnFfwTQnnC5w4nYtXuBc7DIA16BxkA

I just want to remove the trailing part which is _=72HNtUhJkGN5yXngjof0jLZ1yv7ykDfnNwsiYcgx9xqpVoLH0UvC5nneQnFfwTQnnC5w4nYtXuBc7DIA16BxkA

and land on http://www.x3.com/#!/Home

How do I achieve this?

alkar
  • 5,459
  • 7
  • 27
  • 43
Sanjay Salunkhe
  • 2,665
  • 5
  • 28
  • 52
  • This looks like a base64 encoded string. The padding (== characters) gets truncated because = in the URL is used to assign parameters. You should urlencode the string so that equal signs become '%3D'. – alkar Feb 24 '14 at 12:13
  • @alkar but what will that achieve in my question..I actually want to redirect.I am not concerned what comes after .aspx and want to discard this.Do you have any solution – Sanjay Salunkhe Feb 24 '14 at 12:16
  • If you do that, the redirect should work I believe. Can you try visiting the following URL and see if the redirect works? http://www.x3.com/#!/Home?_=72HNtUhJkGN5yXngjof0jLZ1yv7ykDfnNwsiYcgx9xqpVoLH0UvC5nneQnFfwTQnnC5w4nYtXuBc7DIA16BxkA%3D%3D – alkar Feb 24 '14 at 12:17
  • @alkar I am getting /Home?_=72HNtUhJkGN5yXngjof0jLZ1yv7ykDfnNwsiYcgx9xqpVoLH0UvC5nneQnFfwTQnnC5w4nYtXuBc7DIA16BxkA%3D%3D – Sanjay Salunkhe Feb 24 '14 at 12:20
  • Oops sorry, misread one bit of the question. From your redirect statement in nginx try to remove `$1`. It should fix this. – alkar Feb 24 '14 at 12:23
  • @alkar Ok will try.thanks..Should i keep permanent or remove that too – Sanjay Salunkhe Feb 24 '14 at 12:24
  • @alkar No it didn't work – Sanjay Salunkhe Feb 24 '14 at 12:31
  • Permanent depends on the type of redirection you want. Make sure you have disabled your browser's cache before testing. Due to the permanent keyword if you're using the cache it will not work. – alkar Feb 24 '14 at 12:31
  • @alkar Still dint work – Sanjay Salunkhe Feb 24 '14 at 12:34
  • Try to change it back to `/#!/Home$1?` (notice the extra question mark at the end). – alkar Feb 24 '14 at 12:36
  • @alkar Yess It worked ..Thanks a lot ..Can you please give it as answer as i can give you a upvote and it can help others like me – Sanjay Salunkhe Feb 24 '14 at 12:40
  • possible duplicate of [Remove parameters within nginx rewrite](http://stackoverflow.com/questions/9641603/remove-parameters-within-nginx-rewrite) – Michael - sqlbot Feb 24 '14 at 12:54

1 Answers1

2

You need to add a trailing ? to the rewrite url as per the docs:

rewrite (?i)^/abc/HomePage.aspx(.*) /#!/Home$1? permanent;

Make sure to clear the browser cache before testing.

Also, regarding permanent redirection refer to this answer.

Community
  • 1
  • 1
alkar
  • 5,459
  • 7
  • 27
  • 43