6 replies
Here's a question for the techies out there.

I've recently had to re-organise one of my websites thanks to a webhost who I no longer do business with.

The upshot of this is I used to have everything installed in a sub-domain and I don't anymore.

What I want to do is to do a redirect so anytime anyone looks for anything under the /cms folder, whether it is cms/header.jpg or cms/bob/folder/index.php they are redirected to the root of the website.

I've been scratching my head on this for an hour now and am completely stuck.

Any advice / help would be massively appreciated!


#question #redirect
  • Profile picture of the author Nigel Greaves
    Hi Jason,

    Here's a good guide to using mod_rewrite that I think covers what you're looking to do:

    URL Rewriting | redirecting URLs with Apache's mod_rewrite || HTMLSource ]

    Hope it helps,

    {{ DiscussionBoard.errors[1175717].message }}
  • Profile picture of the author ecoverdesign
    Hello Jason,

    basically you just need to create a .htaccess file with the following content:

    RedirectMatch ^/cms/.* http://www.yourdomain.com/

    Replace yourdomain.com with your own domain name and upload the .htaccess to the root of your domain.


    Graphics Design, Development and Webmaster Services

    {{ DiscussionBoard.errors[1175724].message }}
  • Profile picture of the author CmdrStidd
    Jason, I can sympathize with your situation. You can do what is called a 301 redirect inside the .htaccess file and you wont lose any of your page rank this way. Just remember that it is a 301 (which is the code for a permanent move) and not a 302 (which is the code for a temporary move). The line of code would look something like this:

    redirect 301 /old/old.htm http://www.you.com/new.htm

    And as far as I know, mind you I have only done this once, but you have to do this for each page that has moved. Now, I could be wrong about that so it might not hurt to google 301 redirect and see if there is another way that is quicker.

    I hope that helps.

    {{ DiscussionBoard.errors[1175726].message }}
    • Profile picture of the author Alex Williams

      I always do what Dana suggests - a 301 redirect in my .htaccess file.

      If you have no htaccess, just create one. Start with a blank notebook file and name it .htaccess.txt. Then rename to .htaccess in Total commander or similar file manager.

      In the file, below any lines if you have them, or in a blank file, you should write the line like this:

      redirect 301 /cms yourrootdomainlink.com, with the http and www prefix
      (sorry cannot post links because my account is too young here )

      I am not sure though whether you should redirect ALL the files separately that are in the CMS directory - just try and you will see.

      I can help you on a messenger if you still need help, just PM me for that.

      {{ DiscussionBoard.errors[1175793].message }}
  • Profile picture of the author Jason Johns
    Oh warriors, you are truly the most amazing resource on the planet!

    Using Thomas's suggestion to redirect anything beneath the CMS directory and the redirect function from within cpanel to redirect the CMS directory itself it has worked!

    Now I will not be getting several hundred 404's a day

    Dana's suggestion would work, but there are several hundred files (it's a complete CMS system). However, I imagine you could adjust it with a wildcard to make it work.

    Thank you ever so much!

    This is a useful function that I will take note of as I am sure to use it again.

    Wishing you all the best

    {{ DiscussionBoard.errors[1175836].message }}
  • Profile picture of the author CmdrStidd

    I do not mean any disrespect to Thomas, but you need to check and see if his method will still keep your page rankings for those pages or if you lose that using his method. I don't know one way or the other but I do know that using the 301 you keep the page rankings in the search engines.

    It may be that Thomas's way retains them too since it is still done in the .htaccess file but you need to check on that to be sure. If you do keep the page ranks then his is much simpler and easier to use. Do me a favor and let us know if that way keeps the page rank or if it is lost using that method? I would definitely like to know.

    Thomas: Nothing against you but if someone has worked hard to get a certain page rank, they don't really want to lose it because of a redirect. I am sure you understand. That is my only concern and hey, if you keep the ranking with the SE then you have taught me something here.

    {{ DiscussionBoard.errors[1175848].message }}

Trending Topics