1

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.

2
  • almost forgot here's the current htaccess – user6991 Apr 20 '11 at 17:46
  • this is the one that's closest to what I'm trying to do pastebin.com/tpSegYLp – user6991 Apr 20 '11 at 18:08
2

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://httpd.apache.org/docs/2.0/misc/rewriteguide.html#url "per apache docs"

1
  • @Dwight - cool, I hope it did work enough to make it work the way you needed. – Gavin C Jun 3 '11 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy