Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have 3 URLS all pointing to the same site.

  • www.abc.co.uk
  • www.xyz.com
  • www.123abc.org

I have a folder /foo/bar which has lots of sub folders and files in etc. I want to rewrite this to /bar.

So if I have www.abc.co.uk/foo/bar/sheep/page.html I want it to redirect to www.abc.co.uk/bar/sheep/page.html. Is this possible?

Sometime I may have a URL like www.abc.co.uk/foo/bar/foo/page.html so this would become www.abc.co.uk/bar/foo/page.html. Only the first instance of foo would be rewritten.

share|improve this question

2 Answers 2

Yes this is possible. You have to use mod_rewite, which I don't know to much about. Maybe this link will help you: http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html

share|improve this answer

This should be the first step for achieving it:

RewriteEngine On
RewriteRule ^foo/(.*)$ $1 [R]

Still it has a problem – it will redirect URL "/foo/foo/foo/bar/a.html" to "/bar/a.html" as well.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.