htaccess: redirect URL with folders to URL without folders

Posted on 2009-12-21
Last Modified: 2013-11-30
I am trying to add a rule to .htaccess that will redirect URLs containing specific folders.

I wan to redirect any URL containing "/download/zips/" to a URL without "/download/zips/". The folder "/download/zips" no longer exists so I need a redirect and not a rewrite.

For example, if a user entered this URL:

...I want to send them to this URL:

I can't get the regex syntax right. Can anybody help?
Question by:bearclaws75
    LVL 3

    Expert Comment

    This should do it for you and also will help for future redirects : happy redirecting
    LVL 3

    Expert Comment

    301 redirect is the solution for you.
    LVL 3

    Expert Comment

    Redirect /olddirectory/oldfile.html

    Author Comment

    Sorry - neither solution is sufficient.

    The link provided does not explain how to handle this condition.

    A Redirect only works if the URL is known. In my case, I know the middle part of the URL but not the file being accessed, so I need a dynamic solution that will look for "/download/zips/" in the URL string, remove it and redirect the user to the new URL.
    LVL 14

    Accepted Solution

    Try this.

    RewriteEngine On
    RewriteRule (.*)download/zips(.*) /$1$2 [R]

    Open in new window


    Author Closing Comment

    This worked perfectly. Thanks!

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Let’s list some of the technologies that enable smooth teleworking. 
    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now