Forum Moderators: phranque
I've been working on several sites on my WHM/Cpanel server where I'll use fantastico to set up a CMS under a subdirectory of the VirtualHosts document root. (i.e. when installing mambo, I'll install it in /mambo/. Getting to it, then, requires me to type in "http://somedomain.com/mambo/"
I want to set the .htaccess file in the root so that all requests to "http://somedomain.com/" end up going to the subdirectory transparently. After reading several places it looked like what I needed was mod_rewrite, but everything I've tried doesn't work and I just end up with and index listing of my Virtual host root.
I thought this would do it:
RewriteEngine on
RewriteRule ^/$ /mambo/ [R]
I even added "Options -MultiViews" above this working from a clue I saw in another post.
The RewriteRule I got from the apache URL rewriting guide, although it wasn't clear if this would be transparent or act like a typical html redirect. In any case it doesn't work at all.
What am I missing? How do I troubleshoot something like this?
Any help is greatly appreciated.
Welcome to WebmasterWorld [webmasterworld.com]!
For use in .htaccess, omit the leading slash on the RewriteRule pattern.
If you want to rewrite requests for any file in root to the same-named file in /mambo, try something like this:
RewriteEngine on
RewriteRule (.*) /mambo/$1 [L]
Troubleshooting can be difficult. Check your server error logs if you have problems.
Jim
Specifically, I get a "500 Internal server error" when using the rule as written. I saw in another post that Cpanel does things with rewrite and requires the [PT] flag, so I tried that in place of [L], but no joy.
I also tried it with and without Options -MultiViews in the .htaccess file.
Error logs didn't show anything when I was getting the Internal server error. Maybe I'm looking in the wrong place? Is there any way to turn on a debug or verbose logging mode for apache so I can see what it's choking on?
Thanks for your help,
Brian
P.S. The server is running v1.3 if that makes any difference.
Options +FollowSymLinks
You can probably co-exist with Cpanel as long as you always copy the existing .htaccess file from your server before you modify it. Otherwise, changes made with Cpanel will be lost. The real problems with compatibility are between FrontPage Extensions and "manual" .htaccess changes -- that hardly ever works.
If you have server admin privileges, you can enable detailed mod_rewrite logging as described in the mod_rewrite documentation. It's surprising that not even 500 errors show up in your error logs -- I'd suggest contacting your host about that, as it rather leaves you wondering what other errors you might be having and not know about...
You should use [L] even if you do need to use [PT]. Just combine them into [PT,L].
Ref:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]
Jim
tried FollowSymLinks and still got the error.
turned debugging on in httpd.conf, restarted apache and tailed the output:
Now I'm seeing "maximum number of internal redirects reached." -- using just [L] and [PT,L]
I assume this means a looping error?
As you can tell, I do have root access. It's a "managed" virtual server so I have full control although I didn't do the original setup. I'm trying to do things in .htaccess so I can tell others (who won't have root access) how to do the same thing.
Thanks for your help.
The RewriteCond was probably my major problem all along.
So now what I've done is created a symbolic link called main that points to /mambo. My .htaccess file then looks like:
RewriteEngine on
RewriteCond %{REQUEST_URI}!^/main/
RewriteRule (.*) /mambo/$1 [L]
Now I'll create this setup in each Document Root for my hosted websites. Switching to a new "main" website as easy as redoing the symbolic link. So when I want to switch from using Mambo to PHPNuke, I can just create PHPNuke in the subdirectory PHPNuke and relink main to PHPNuke like this:
rm main
ln -s PHPNuke main
and then the new site is in place.
This makes it easy to create a new site that I can work on until I'm happy with it and then swap it in.
This is my document root:
/mambo -- main website running mambo
/gallery -- a php photo gallery
/main -- symbolic link to main website
Using the above .htaccess, I can't get to /gallery without adding a symbolic link in /mambo to point it back to /gallery (ln -s /gallery /mambo/gallery) And even in doing that the URL ends up looking like "http://mywebsite.com/main/gallery"
Is there a way to modify the RewriteCond so that the RewriteRule won't bother /gallery?
I tried adding the line:
RewriteCond %{REQUEST_URL}!^/gallery/
above the other RewriteCond...
but it didn't have any effect.
You can also use:
RewriteCond %{REQUEST_URI} !^/(mambo¦gallery)/
Jim
Both methods do work. What I was seeing was that anytime I'd type in mydomain.com/photos/ the URL would change to mydomain.com/main/photos. I found that this behavior went away when I removed the symbolic link /main/photos which pointed back to /photos.
Now the URLs work as advertised.
Thanks!