1

I want to put an .htaccess file in a directory of my website. For this purpose in:

www.mysite.com/dir/

Then I want anything after /dir/ to direct to /dir/index.html but still display the original URL in the browser. So for example:

www.mysite.com/dir/foo/bar -> www.mysite/dir/index.html

So in essence I want the browser to go to index.html but display the original URL Could this be done with a reverse proxy?

migrated from superuser.com Jan 1 '13 at 6:13

This question came from our site for computer enthusiasts and power users.

  • You could just URL Rewrite in your Htacces file: addedbytes.com/articles/for-beginners/… alternatively if you are using Cpanel you can just do this in your redirection settings. – Sam Jan 1 '13 at 1:29
  • I think this is what you are looking for: RewriteRule ^dir/.*$ index.html [NC,L] Sorry, I'm new at this. Just see if that helps. – Sam Jan 1 '13 at 1:33
  • @Sam that won't work because I want the URL in the browser to stay the same but the browser to display content from index.html – user1036238 Jan 1 '13 at 2:06
1

Sam's second comment was pretty close. This should work:

RewriteRule ^dir/(.*)   dir/index.html [NC,L]
  • But then won't that change the URL displayed in the browser to index.html? I wan't it to display the same URL, the one before the redirect – DontTurnAround Jan 1 '13 at 21:36
  • Nope. It's not doing a redirect. That would look like: RewriteRule ^dir/(.*) dir/index.html [R=301,L] - The R=301 is a 301 Redirect. – Eric Brandel Jan 1 '13 at 21:38
  • Thank you so much! Once I put a RewriteEngine On statement before that it worked perfectly! – DontTurnAround Jan 1 '13 at 23:12
  • @EricBrandel I tried to put this line in the .htaccess file in my site folder's dir, it still get 404 not found issue (because I am doing prettify url with one page app). Any solution? – Ezeewei Jun 2 '15 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.