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 1032505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:05:13+00:00 2026-05-16T14:05:13+00:00

I need to change the url of a directory so that: www.example.com/foo/ becomes www.example.com

  • 0

I need to change the url of a directory so that:

www.example.com/foo/

becomes

www.example.com

I can’t move the files.

Putting a htaccess file using mod_rewrite to simply rewrite http://www.example.com to http://www.example.com/foo wasn’t a problem

RewriteEngine On
RewriteRule !^foo/ foo%{REQUEST_URI} [L]

However I must ensure that if the user requests http://www.example.com/foo that the http status is 404 or the user is redirected to http://www.example.com. Unfortunately whatever I do, it seems to end up in an infinite loop. For example this results in an infinite redirection loop:

RewriteEngine On
RewriteRule !^foo/ foo%{REQUEST_URI} [L]

RewriteCond  %{REQUEST_URI}  ^/foo
RewriteRule  ^foo(.*) http://www.example.com$1 [R=301,L]
  • 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-16T14:05:14+00:00Added an answer on May 16, 2026 at 2:05 pm

    You need to condition on the original request sent to the server, since the %{REQUEST_URI} will change during the mod_rewrite processing, which causes the internal redirect loop.

    Consequently, something like this should take care of things (for the 404, your 301 RewriteRule should work fine as well if you want to swap that in):

    RewriteCond %{THE_REQUEST} ^[A-Z]+\s/foo [NC]
    RewriteRule ^ - [R=404]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a project that I am deploying at www.foo.com/path1/default.aspx and www.foo.com/path2/default.aspx What
I use Pjax with tutorial from http://railscasts.com/episodes/294-playing-with-pjax?view=comments I don't need change url and this
basically need to change the value that - admin_url() returns any idea?
I need to change the value of the url of the onclick portion of
I need change background of all text that have two spaces from the start
i need change color of SystemTray.ProgressIndicator color, how i can do it? I tried
Need to change li position by clicking to move up or to move down.
I have 3 different domains, www.example.com, www.mywebsite.com, www.domain.com. In my server, I have 3
I have an existing page called bfly.php that I need to change to butterfly-jewelry.php
I have a css file that links to images. .test{ background: url(http://site.com/dynamic/test.jpg) no-repeat; }

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.