Domain Manage

Nginx Redirect Help

Discussion in 'Scripts and Coding' started by AssetDomains, Sep 30, 2014.

Thread Status:
Not open for further replies.
  1. AssetDomains United Kingdom

    AssetDomains Well-Known Member

    Joined:
    Feb 2010
    Posts:
    2,952
    Likes Received:
    52
    Anyone here know about redirecting on a nginx server

    what I'm trying to do is redirect some old asp pages to a flat html page on a site I'm reviving for juice.

    I've tried adding
    Code:
    # nginx configuration
    location /index.asp?ID=38 {
    rewrite ^(.*)$ [URL]http://www.newsite.org.uk/cumbria.htm[/URL] redirect;
    }
    location /index.asp?ID=39 {
    rewrite ^(.*)$ [URL]http://www.newsite.org.uk/greater-manchester.htm[/URL] redirect;
    }
    
    to the config file but now joy I think its something to do with the ? not being escaped properly but I'm dammed if I know how to fix it.

    I used to think .htaccess was confusing but trying to find stuff on this is a pain in the backside
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
     
  3. mrt United Kingdom

    mrt Member

    Joined:
    May 2013
    Posts:
    18
    Likes Received:
    3
    You need to escape the question marks and the rewrites should probably be in your "location /" block, like so:

    Code:
    location / {
      rewrite index.asp\?ID=38 http://www.newsite.org.uk/cumbria.htm redirect;
      rewrite index.asp\?ID=39 http://www.newsite.org.uk/greater-manchester.htm redirect;
    }
    Also it's worth noting that the 'redirect' flag is a temporary redirect (302) - if you want a permanent redirect (301) use the 'permanent' flag instead.
     
  4. AssetDomains United Kingdom

    AssetDomains Well-Known Member

    Joined:
    Feb 2010
    Posts:
    2,952
    Likes Received:
    52
    Thanks it didn't quite work how I needed it

    but I've figured out htaccess can actually work with the vps I'm on so sorted it now anyway
    Thanks again for having a look
     
Thread Status:
Not open for further replies.

Share This Page