Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Its been about three years since I've played with apache and php(I've been using thin and nignx ;). So I've forgotten how to setup a mod_rewrite directive to forward all http requests from root to the application's installed folder.

Current setup and restrictions:

  • The site is on a shared cpanel hosting service that doesn't allow applications being installed as root (feature not a bug in my book for versioning and what not).
  • CMS application was installed under joomla-1.5.60/
  • I need to setup /(.*) to redirect to /joomla-1.5.60/$1 but still look to the browser as /(.*)
  • RedirectMatch does not work
  • I cannot establish docroot as the application's root because of account restrictions

I've read over the docs by apache and I keep getting a redirection loop. So any help you guys can provide would be appreciated.

Thanks, D.

share|improve this question
    
almost forgot here's the current htaccess –  Dwight Spencer Apr 20 '11 at 17:46
    
this is the one that's closest to what I'm trying to do pastebin.com/tpSegYLp –  Dwight Spencer Apr 20 '11 at 18:08
add comment

1 Answer 1

up vote 1 down vote accepted

In case you didn't get this sorted out, looking at the rewrite rule you have in your pastebin link

RewriteRule ^(.*)$ http://www.diviniti.cc/joomla-1.5.20/$1 [R=301,QSA,L]

there's a few things that are defeating your desires here:

  • the R=301 directive will make the browser actually 'go away' and load up the rewritten url, changing the URL in the browser
  • your desire to also redirect any non-www subdomains to a www subdomain also conflicts with your desire to keep the joomla part of the URL hidden from the browser.

Instead try two rules:

Options +FollowSymlinks
RewriteEngine On

# 1. redirect (bounce) all non-www to www [as per apache docs][1] - retaining query strings
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.example.com/$1 [L,R,QSA]

# 2. then, use joomla but hide the joomla dir - note the lack of 'R' directive
RewriteRule ^(.*)$ /joomla-1.5.20/$1 [QSA,L]

If you don't care about enforcing the "all subdomains should be www" just skip rule #1, leave rule #2.

You don't need the second rewrite you had in your pastebin, for the 'root':

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(*.)?diviniti\.cc$
RewriteRule ^(/)?$ joomla-1.5.20/index.php [L]

because the ^(.*)$ in my supplied rewrite also matches the case where the url is http://www.example.com/

Now, it's possible that Joomla itself will not be happy with this chicanery, it may deeply not like being at this pseudo-root while the documentroot says something else and it's possible it will barf.

1 : http://www.purpleslurple.net/ps.php?theurl=http://httpd.apache.org/docs/2.0/misc/rewriteguide.html#purp130 "per apache docs"

share|improve this answer
    
Thanks Gavin, that helped a lot. –  Dwight Spencer Jun 2 '11 at 18:17
    
@Dwight - cool, I hope it did work enough to make it work the way you needed. –  Gavin C Jun 3 '11 at 15:03
add comment

Your Answer

 
discard

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

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