views:

190

answers:

2

All,

I want to redirect all traffic that comes to http://mysite/ to http://mysite/public folder. Currently I am doing this using the below in an .htaccess file and it works for the root directory. But if I browse to http://mysite/application, it doesn't redirect and shows the directory listing. I want all traffic regardless of what folder it is to redirect to http://mysite/public folder

RedirectMatch permanent ^/*$ /public/

Thanks

+1  A: 

Try this mod_rewrite example:

RewriteEngine on
RewriteRule !^public/ /public%{REQUEST_URI} [L,R=301]
Gumbo
If I browse to http://mysite/application, it's redirecting to http://mysite/public/application. It should redirect to http://mysite/public instead..
Vincent
then you should be able to just remove %{REQUEST_URI} surely?
Tomba
tried that.. it didn't work..
Vincent
@Vincent: So just anything not `/public` should be redirected to `/public`?
Gumbo
hmm..actually it did work, but it doesn't seem to execute the index.php code properly, mostly because of another htaccess rule in "public" folder as under:RewriteEngine on# The leading %{DOCUMENT_ROOT} is necessary when used in VirtualHost contextRewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -dRewriteRule ^.*$ - [NC,L]RewriteRule ^.*$ index.php [NC,L]
Vincent
@Gumbo: yep. That's right
Vincent
@Vincent: Then use this rule: `RewriteRule !^public$ /public [L,R=301]`. But you should know that there will no other URL path work than `/public` since, well, anything not `/public` is being redirected to `/public`.
Gumbo
hmm.. So, if internally the code refers to anything except /public folder, it will redirect to /public folder? That might not work for me.. I just wanted the user to redirect to /public folder from the browser, so it doesnt list directory structures and files..
Vincent
A: 

I see that you're using Zend Framework. Zend uses 'public' as the exposed web folder, but you should use the folder dictated by your web host. What is the name of the server-side folder that is exposed to the web? Your file structure should be like this:

application/
[web_exposed_dir]/
library/

In my case, the [web_exposed_dir] is called 'content'. You won't have to redirect everything to 'public' if you do it the way I've outlined.

Sonny