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

  • Home
  • SEARCH
  • 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 441807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:00:33+00:00 2026-05-12T21:00:33+00:00

I have this rewrite rule that turns foo.com/test (or foo.com/test/) into foo.com/test.txt: RewriteRule ^test/?$

  • 0

I have this rewrite rule that turns foo.com/test (or foo.com/test/) into foo.com/test.txt:

RewriteRule ^test/?$ test.txt [NC,L]

It works perfectly and, importantly, never reveals to the user that the “real” URL is foo.com/test.txt.

Now I want to do the same thing where the “real” URL is foo.com/testdir, where testdir is a directory:

RewriteRule ^test2/?$ testdir [NC,L]

It does the rewrite but it shows that rewrite to the user. Not what I want.

Can anyone explain what Apache is thinking here, and the best solution? Just rewriting to testdir/index.php doesn’t work for me since then the code in index.php doesn’t have the right working directory. (It runs as if it were foo.com/index.php and the css files and whatnot are in foo.com/testdir/.) Perhaps the right solution is to change the contents of index.php to refer to testdir/foo.css instead of just foo.css but I’m lazy. Also, I’d rather the rewrite rule didn’t have to know whether it’s index.php or index.html or what-have-you.

Addendum

Thanks to the first answer, I now see the essence of my problem: If I want the user to use the URL me.com/foo and get to the “real” URL me.com/somedir then I have to pick between two undesirable things:

  1. The URL gets visibly rewritten (the user can see me.com/somedir).
  2. The stuff in somedir runs as if it’s in the root directory. So I have to change all the paths in somedir/index.php, for example. Like “somedir/style.css” instead of just “style.css” like I used when going straight to the “real” URL, me.com/somedir

I’m thinking the only answer to this is to suck it up and change those paths. Or just rename the directory “somedir” to “foo” but I can’t do that for other reasons.

  • 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-12T21:00:33+00:00Added an answer on May 12, 2026 at 9:00 pm

    Add the trailing slash:

    RewriteRule ^test2/?$ testdir/ [NC,L]
    

    http://foo.com/testdir isn’t a valid url to the directory, Apache looks for a file called testdir, and because testdir is actually a directory Apache tries to fix it by redirecting to testdir/ . So while your rewrite worked the subsequent missing slash error was fixed by redirecting to testdir/.

    You may also need to add a base href tag to the head of your document or relative links will break:

    <base href="/">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try changing the element’s width instead of its CSS width.… May 12, 2026 at 9:00 pm
  • Editorial Team
    Editorial Team added an answer Shouldn't it be like: Aggregate((a, b) => string.Format("{0}<ID>{1}</ID>", a,b)) You're… May 12, 2026 at 9:00 pm
  • Editorial Team
    Editorial Team added an answer Meh... apologies guys, I was pointing my repository at my… May 12, 2026 at 9:00 pm

Related Questions

I purchased a domain: josecvega.com Whenever someone tries to access http://www.josecvega.com it forwards them
On my Joomla site, I've added some fairly straight-forward RewriteRules to my .htaccess file.
I have a cakephp installation in the root of my domain. Now it turns
I'd like to use mod_rewrite to make pretty URLs, but have a single version
I'm really struggling with this regex. We're launching a new version of our groups

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.