I have a server running on XAMPP in LAN.

In htdocs I've created subfolder called 'apps' (it's because I'm using one CodeIgniter's files to multiple webpages).

Now, when somenone want to visit a webpage, must visit: http://myserver/apps/app_name.

Is it possible with .htaccess (or else) to skip that /apps/ part? http://myserver/app_name ?

1 Answer 1


Activate mod_rewrite, and put this in a .htaccess file or a <Directory> directive:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^apps/
RewriteRule (.*) apps/$1

What it does:

The first three lines check if the requested URI refers to an actually existing file, directory or link, in order to make sure that e.g. an index.html at top level is still delivered if requested.

The fourth line makes sure that the user has not already requested an URI in the apps/ subpath.

If the requested URI is not an existing file, directory or link and does not start with apps/, the path of the URL is taken and apps/ is prepended. This only happens internally.

  • thanks for your help. I have last one questions. How to hide that /app/ part from url?
    – breq
    Commented Jun 4, 2014 at 6:20
  • It should not be visible, if you just enter http://yoursite.com/foobar, as the rewriting to http://yoursite.com/apps/foobar is only done internally. If you want to redirect all paths starting with apps/ to strip that part, this rule should do, if placed before the other ones: RewriteRule ^apps/(.*)$ $1 [R=301,QSA,L]. It does a 301-redirect, you can change the http status code by changing the R=301. The QSA appends any parameters the original URL had to the new URL, and the L stops further rewriting the request after that rule in order to send out the redirect to the browser.
    – Jost
    Commented Jun 4, 2014 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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