Mod rewrite for removing a folder name from URL

Dear guys,

What I tried to do is to remove a folder from URL.

For example www.example.com/app into www.example.com.

Seems not a big deal but… let see details.

My Problem details

  1. I create a new web app from command line like in the first yii app steps. (I named the web app folder as "htdocs" instead of "testdrive")

So let say the base folder of this whole application is /var/www/myapp/.

With these folders inside.


/framework/

/htdocs/


(/requirements/ removed)

  1. For URL bountifulness’s sake remove index.php from URL using index.php hidding with url manager. This works fine.

  2. For security’s sake, I move “protected” folder out from “htdocs”.

So, now it becomes.


/framework/

/htdocs/

/protected/

And I use apache to create virtual host for my web site and set www.example.com to point to /var/www/myapp/.

It would be easy if I just create virtual host and point to /var/www/myapp/htdocs/. But no I can’t, I can’t touch the server setting.

So when I run my application it will be like www.example.com/htdocs/ so … I want to remove those /htdocs/.

.htaccess that I used

Up until now I used 2 .htaccess

  1. Located at base folder



Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule    ^$ htdocs/    [L]

RewriteRule    (.*) htdocs/$1 [L]



  1. Located inside /htdocs/



RewriteEngine on

# forward everything to index.php

RewriteRule . index.php



By doing this /htdocs/ always appear in the URL, so what should I do the remove the folder in URL.

Thanks in advance :)

You can try the following code




<IfModule mod_rewrite.c>

Options +FollowSymlinks

RewriteEngine on

RewriteBase /htdocs/


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php [L]


</IfModule>



Thanks, I will. I guess I should put this in /htdocs/ right? Anyway I’ll try :)

Hi, have you resolved this? I have the same problem.

Thanks