1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Quick htaccess redirect from subfolder?

Discussion in 'Site & Server Administration' started by patrich, Dec 18, 2008.

  1. #1
    Could someone please tell me how to use .htaccess to redirect the following:
    SEMrush
    mydomain.com/subfolder to
    mydomain.com

    I am sure this is a stupid question but I have been looking for hours and haven't found an answer yet.

    Thank you for your help!
     
    patrich, Dec 18, 2008 IP
    SEMrush
  2. pr0t0n

    pr0t0n Active Member

    Messages:
    244
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    78
    #2
    Make an .htaccess file with this lines, and put it into that specific folder:

    
    RewriteEngine On
    RewriteRule ^.*$ / [R=301,L]
    
    Code (markup):
    That rule should redirect every attempt to open any file or subfolder or subfolder/file to your root url. Make sure you are uploading your .htaccess file with those rewrite rules to that specific folder, and not in your root html folder of your site.
     
    pr0t0n, Dec 19, 2008 IP
  3. Reca

    Reca Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Hi pr0t0n,
    I have a similar problem: I need to do the redirect in this way:
    mydomain.com/subfolder/subfolder1/subfolder2/
    to
    mydomain.com

    Following your instructions works only for the first subdirectory (mydomain.com/subfolder/ to mydomain.com)
    Do you have any suggestions to be able to realize what is necessary?

    Regards, Max
     
    Reca, Aug 30, 2018 IP
  4. Steven74

    Steven74 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    You can also put a single .htaccess at the root of your website:

    
    RewriteEngine On
    RewriteRule ^subfolder/(.*)$ / [R=301,L]
    
    Code (markup):
     
    Steven74, Aug 30, 2018 IP
  5. Reca

    Reca Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Another small problem: there are some static pages that are called as the folder.
    By setting the rule they are wrongly redirected too
    For example, mydomain.com/subfolder.html is redirect to home page because in the .htaccess file there is the rule RewriteRule ^subfolder/(.*)$ / [R=301,L]
    How can I prevent these static pages with the same folder name from not being redirected?

    Regards, Max
     
    Reca, Sep 6, 2018 IP