301 Redirect Site With Exceptions?

Discussion in 'Site & Server Administration' started by PalSys, Jul 24, 2014.

  1. #1
    Hello folks :) I'm trying to do a permanent redirect on a website to a new domain via .htaccess, but I need there to be exceptions to that redirect. For example, some posts and pages will remain there so should not be redirected.

    I've tried writing conditions a few different ways, but no luck in getting an URL exception to work. Any ideas? Redirecting page by page just isn't an option.

    Thanks in advance for any help!
     
    PalSys, Jul 24, 2014 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,798
    Likes Received:
    4,531
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Any particular reason you want to use .htaccess and not from an existing include like a config file (dirty but effective)?
     
    sarahk, Jul 24, 2014 IP
  3. PalSys

    PalSys palsys.io

    Messages:
    2,628
    Likes Received:
    224
    Best Answers:
    0
    Trophy Points:
    230
    #3
    @sarahk

    No reason at all - I'm happy to take whatever route is effective and institutes a clear 301 for SEO purposes. I'm not sure I follow on the idea of a config file executing redirects though?
     
    PalSys, Jul 25, 2014 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,798
    Likes Received:
    4,531
    Best Answers:
    123
    Trophy Points:
    665
    #4
    The config file is just one that every page calls and is a useful place to put the check - dirty but effective. Config files get called before anything is output to the browser so header() commands can still be called.

    Check to see if the requested url is one of the ones you are keeping and continue or else do the header() command and exit.
     
    sarahk, Jul 26, 2014 IP