In my server I have the following folder structure and I want to display each folder project link without the folder name. How can I do this?

Root Folder
  -> Subfolder1
     -> Project folder 1
     -> Project folder 2
  -> Subfolder2
     -> Project folder 3
     -> Project folder 4
  -> Subfolder3
     -> Project folder 5

I want to display my project URL without the subfolder, ie:

www.domain.com/project folder 1
www.domain.com/project folder 2
  • if you do not want folder in URL then how you need URL? – Helping Hands Mar 12 '15 at 7:40
  • How many different projects (and subfolders) do you have? Is there any naming pattern that links the subfolder with the project folder? Do you have access to the server config, or are you limited to just .htaccess? – MrWhite Mar 12 '15 at 8:29
  • Thanks for your reply.Currently i have 3 subfolder and there will be multiple project inside each subfolders.There is no naming pattern and now I just want to limit via htaccess. – Alisons Bg Mar 12 '15 at 8:36

You need to know the relationship between the project-folder and the sub-folder, ie. which sub-folder a particular project is in. If there is no pattern between project-folder and sub-folder and being restricted to .htaccess then I think you'll need to specify each rewrite manually.

You can internally rewrite all requests for the respective project to include the appropriate sub-folder.

RewriteEngine On

RewriteRule ^project-folder1.* /sub-folder1/$0 [L]
RewriteRule ^project-folder2.* /sub-folder1/$0 [L]
RewriteRule ^project-folder3.* /sub-folder2/$0 [L]
# etc...

Note that this is an internal rewrite, not an external redirect, the URL in the address bar won't show the sub-folder.

  • 1
    Thanks for your answer.It works for me.I just made little bit changes. RewriteCond %{DOCUMENT_ROOT}/wordpress/$1 -f [OR] RewriteCond %{DOCUMENT_ROOT}/wordpress/$1 -d RewriteRule ^(.*)$ /wordpress/$1 [L,NC] RewriteCond %{DOCUMENT_ROOT}/codeigniter/$1 -f [OR] RewriteCond %{DOCUMENT_ROOT}/codeigniter/$1 -d RewriteRule ^(.*)$ /codeigniter/$1 [L,NC] – Alisons Bg Mar 12 '15 at 10:09
  • Please advice if i make any mistakes in my code.Although It works fine. – Alisons Bg Mar 12 '15 at 10:16
  • That is quite a different method, but yes, it should work OK. That is certainly better if you have lots of projects and avoids having to update the .htaccess file when you add more projects, providing they are within one of a few top-level subfolders. However, it is perhaps less efficient since every request will be processed. – MrWhite Mar 12 '15 at 12:49
  • Now this is not working in case of sub domains.The projects are moved to sub domain like demo.domain.com.But now the project files cannot access without direct path.Please advice any solution. – Alisons Bg May 9 '15 at 10:30
  • @AlisonsBg If the projects are now on subdomains then you are not going to be able to internally rewrite www.example.com/demo to demo.example.com - if that is what you mean? You will need to externally redirect the request. But presumably the purpose of using subdomains is to have them visible anyway? – MrWhite May 12 '15 at 16:37

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.