views:

296

answers:

3

Ok, so I really don't know much about mod_rewrite and I'm looking over the apache docs and still not figuring this out.

Here is my htaccess (which is mostly just copy & pasted from a site I found): .htaccess in base dir:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [L]
    RewriteRule    (.*) public/$1    [L]
 </IfModule>

.htaccess in /public dir:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

</IfModule>

Basically I'm using the above htaccess files on my current test server and it works great and exactly like I would expect (everything gets seamlessly redirected to public dir).

Now when I throw this on my GoDaddy hosting account i get "Internal Server Errror". I've done some searching and I'm fairly certain I should be able to use mod_rewrite with GoDaddy.

I suspect this is because I'm not using the base directory to host the site in. The site is in in the folder html/myapp/ (where html is the base directory) and i have a subdomain set up in GoDaddy to look in that folder.

Edit:

After checking the error logs I see this-

[Wed Apr 21 17:59:45 2010] [error] [client] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.

So I assume I've created some sort of infinite loop? But I'm not sure how...

A: 

Have you tried:

Options +FollowSymlinks
RewriteEngine on

I remember having trouble getting mod_rewrite working on godaddy.

Instead of using [L] try using [R=301,L]. R=301 means redirect with status code 301 (Moved permanently). If you want to see the other status codes see here. If you don't actually redirect, the .htaccess on the root directory would get called repeatedly.

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [R=301,L]
    RewriteRule    (.*) public/$1    [R=301,L]
 </IfModule>

The way you had it wouldn't send people to the public directory. And I believe that it is looping.

Edit: This should explain the looping.

Edit 2: Instead of (.*) try using ^(.*)$. Other than that, I'm somewhat at a loss.

zipcodeman
hmm.. no dice. Still "500 Internal Server Error". Thanks for the quick response though.
John Deerhake
hmm with that I get an loop error even on my local machine:This webpage has a redirect loop.The webpage at http://localhost/home/jdeerhake/site/home/jdeerhake... has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
John Deerhake
Still same looping problem with that. Thanks for the attempt though :) I'll keep looking and possibly bug someone at GoDaddy if I have to.
John Deerhake
Using 301 wouldn't really fix his problem anyway, since that would cause the "public" part to show up in his URL (something I'm assuming he does not want to happen, but feel free to correct me if I'm mistaken).
Greg W
Yeah, I would rather not have it like that. However I would be happy for the time being with anything that actually worked. haha.
John Deerhake
A: 

The "Internal Server Error" makes me think that GoDaddy might have left mod rewrite turned off for your host. Its happened to me at least a couple times on different hosting companies. I would double check with their support first before wasting too much time on it, just to be on the safe side.

You should also check to see if they provide any form of apache error logging. If you have access to the apache log it should be fairly simple to determine the source problem.

Edit: I got the infinite loop deal when I tried it locally as well. I think you need to add a conditional to stop that from happening. This seemed to work on my machine:

RewriteCond %{REQUEST_URI} !public
RewriteRule (.*) public/$1 [L]
Greg W
Thanks for the advice. Mod_rewrite is enabled. I checked the error logs (not sure why that didn't occur to me before) and I just updated my question. Thanks again.
John Deerhake
My local config still works with that, but no luck on the GoDaddy site. I still get the 500 Error and the the error log shows the same 'max number of redirects' error.
John Deerhake
I'm suspecting that my subdomain is a virtual host and that that is somehow causing these problems.
John Deerhake
+1  A: 

Ok I got it working. heres what I did:

for the .htaccess in the root directory:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule    ^$    /public/    [L]
    RewriteRule    (.*) /public/$1    [L]
</IfModule>

and for the one in /public:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /public/index.php?url=$1 [PT,L]

</IfModule>

I'm honestly not sure why this works, but it does. Thanks to all that helped.

John Deerhake