Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:12:04+00:00 2026-05-26T05:12:04+00:00

I’m having a bit of trouble figuring out something that should be simple. I

  • 0

I’m having a bit of trouble figuring out something that should be simple. I want to 301 redirect everything in a directory to one single file in a new location.

In my .htaccess, I’ve already tried the following…

Redirect 301 /myDir/ http://www.mydomain.com/myNewDir/index.html

and this…

Redirect 301 /myDir/ http://www.mydomain.com/myNewDir/

and this…

Redirect 301 /myDir http://www.mydomain.com/myNewDir

The problem is that each of those are simply mapping each file within /myDir/, and appending it to the end of the destination URL.

After Googling, I saw something that said to do this…

Redirect 301 ^/myDir(.*) http://www.mydomain.com/myNewDir

But that just does the same thing… it’s mapping the existing file location to the end of the URL.

It was easy finding lots of “.htaccess redirect” tutorials online but they seem to only show the obvious examples like ‘one-to-one file mapping’ or ‘one-to-one directory mapping’. These tutorials also seem to neglect explaining the various relevant file directives and how to properly use them.

This particular hosting account is garbage and also has FrontPage extensions installed. Mod-rewrite fails (breaks the whole site) yet the Redirect 301 lines are operating fine. So until I can move this new (non-FrontPage) site to a more robust hosting account, I’ll need to stick with the Redirect 301 one-liner.


How can I simply use a Redirect 301 to redirect everything within /myDir/ to the same single file located at /myNewDir/index.html? (I’d prefer using just /myNewDir/ if possible). Kindly explain, in detail, the file directives used in your solution.


UPDATE:

Previously accepted answer is not working.

Example:

RedirectMatch 301 /myDir1/(.*) http://mydomain.org/newpath/myDir1/index.html

…is giving a “Too many redirects occurred trying to open” error.

This is because /myDir1/(.*) is matching anyplace within the string so if the target URL contains /myDir1/ anywhere, not just the root, it will get redirected into a nasty loop.

See my own posted answer for correct solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:12:04+00:00Added an answer on May 26, 2026 at 5:12 am

    I found the answer within one of my old projects.

    Redirect 301 is all wrong for this. I really wanted RedirectMatch 301 instead.

    RedirectMatch 301 ^/myDir/(.*) http://www.example.com/myNewDir/
    

    Explanation(s):

    http://httpd.apache.org/docs/1.3/mod/mod_alias.html#redirectmatch

    “This directive is equivalent to Redirect, but makes use of standard
    regular expressions, instead of simple prefix matching.”

    http://www.zytrax.com/tech/web/regex.htm

    “The ^ (circumflex or caret) outside square brackets means look only at
    the beginning of the target string, for example, ^Win will not find
    Windows in STRING1 but ^Moz will find Mozilla.”

    and…

    “The . (period) means any character(s) in this position, for example,
    ton. will find tons, tone and tonneau but not wanton because it has no
    following character.”

    and…

    The * (asterisk or star) matches the preceding character 0 or more
    times, for example, tre* will find tree (2 times) and tread (1 time)
    and trough (0 times).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.