Mobile app version of vmapp.org
Login or Join
LarsenBagley505

: How to setup mod_rewrite/htaccess to do url masking and forwarding to a subdirectory? Its been about three years since I've played with apache and php(I've been using thin and nignx ;). So I've

@LarsenBagley505

Posted in: #301Redirect #Apache #ModRewrite #Redirects #Url

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/ 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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @LarsenBagley505

1 Comments

Sorted by latest first Latest Oldest Best

 

@Speyer207

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

RewriteRule ^(.*)$ www.diviniti.cc/joomla-1.5.20/ [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 ^/(.*) www.example.com/ [L,R,QSA]

# 2. then, use joomla but hide the joomla dir - note the lack of 'R' directive
RewriteRule ^(.*)$ /joomla-1.5.20/ [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 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 : httpd.apache.org/docs/2.0/misc/rewriteguide.html#url "per apache docs"

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme