Find the answer to your Linux question:
Results 1 to 3 of 3
If this has already been solved elsewhere, please feel free to provide me a link. I've looked around, and there seem to be so many different kinds of issues related ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    18

    htaccess problem


    If this has already been solved elsewhere, please feel free to provide me a link. I've looked around, and there seem to be so many different kinds of issues related to re-writing that it's hard to find exactly what I need.

    I'm setting up a Zend Framework application on a shared server. Usually, it's pretty easy to set up htaccess for this. The basic structure is this:

    /application/
    /library/
    /public/

    I usually configure apache to rewrite all requests to the given domain so that it goes right into the public folder where there's an index.php file that handles everything. There's also an .htaccess file in the public folder that doesn't allow index.php to take over the request if it's for a real file (like css or an image or something). All basic stuff.

    The problem now is that I've been given an FTP account to a shared server, with the absolute path like this:

    /data/17/2/124/74/2776400/user/3052774/htdocs

    I only have access to htdocs. So my application structure is going to become this:

    /data/17/2/124/74/2776400/user/3052774/htdocs/application/
    /data/17/2/124/74/2776400/user/3052774/htdocs/library/
    /data/17/2/124/74/2776400/user/3052774/htdocs/public/

    All the requests to the domain get routed right to htdocs, and I don't have the option to change it to go right into public. So what I want to do is a) prohibit access to the application and library folders, and b) re-route all traffic to the public folder so that the public folder isn't visible in the URI. Does that make sense?

    It's driving me crazy. What I have so far in the htdocs folder is this htaccess file:

    Code:
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^(www[dot])?domain[dot]com$
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^(.*)$ /public/$1
    
    RewriteCond %{HTTP_HOST} ^(www[dot])?domain[dot]com$
    RewriteRule ^(/)?$ /public/ [L]
    Then inside the public/.htaccess file I have this:
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
    It works sometimes. Sometimes the CSS doesn't load. Sometimes I get errors like "200 OK...The server encountered an internal error or misconfiguration and was unable to complete your request." So the same request is working in different ways, and I can't figure out how to configure things right. I'd rather just use "htdocs" as the public folder and place the application and library folders above it, but I don't have permission to do this.

  2. #2
    Just Joined!
    Join Date
    Dec 2011
    Posts
    18
    UPDATE: I found a place in the control panel to point requests into htdocs/public folder, so now that part is fixed. It says it might take up to 24 hours to make that change? Seems a little extreme.

    The part that is still stumping me might be a hosting problem. Maybe I just need to wait 24 hours, but this is really strange. Have any of you experienced this before? I can refresh the page over and over again. Sometimes the page displays correctly. Sometimes the CSS file is missing. Sometimes I get the message: "The server encountered an internal error or misconfiguration and was unable to complete
    your request." Error logging is enabled but the logs are empty. The host is network solutions. I don't even know how to track down this error! My setup is pretty simple now.

    Requests are pointed directly here:
    /data/17/2/124/74/2776400/user/3052774/htdocs/public/

    So the only publicly-accessible data is in the public folder, things like css, images. js, etc.

    Everything else (application and library folder) is outside of the public folder:

    /data/17/2/124/74/2776400/user/3052774/htdocs/application/
    /data/17/2/124/74/2776400/user/3052774/htdocs/library/
    /data/17/2/124/74/2776400/user/3052774/htdocs/public/

    The .htaccess file in my public folder now looks like this:

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
    Seems pretty straight-forward. I can't figure out why the page doesn't do the same thing each time I request it. Any thoughts on how to trouble-shoot this? Thanks.

  3. #3
    Just Joined!
    Join Date
    Dec 2011
    Posts
    18
    Awesome! 102 viewers! Turns out there's probably not much you guys could have suggested. It was mostly configuration issues I had to get right. The first thing I did was modify the domain DNS settings so point directly into the /data/17/2/124/74/2776400/user/3052774/htdocs/public/ folder. I really don't believe this is a true DNS setting, but it's under DNS settings on the control panel I was using. I'm used to doing this by hand in an apache config file, but I didn't have the option this time. So that was the first part.

    The second part was setting up the Zend Framework like usual with the standard .htaccess file in the public folder. The was the last piece of code I presented above. However, the final problem was that IE showed the page fine, but I kept getting errors in Chrome and Firefox. If I kept refreshing the page, I'd sometimes get no CSS styles, sometimes the page would look normal, and sometimes I'd get this error:

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    The server wouldn't have any logs and I couldn't figure out what the issue was. Somewhere I read it could be due to htaccess, and there were two things I changed. First, I didn't quite get this line:

    Code:
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
    It seemed to be saying to only rewrite to index.php if the file's extension wasn't an image or css file. But I'm pretty sure that's already handled above with these lines:

    Code:
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    So I took that out and things seemed a little better. The page loaded faster, but I still saw the error every so often. I discovered a post on a "Network Solutions" site that said this could be do to the .htaccess file missing this line:


    Code:
    RewriteBase /
    I added that and all my issues went away in all browsers. So now my .htaccess file in the public folder looks like this:

    Code:
    SetEnv APPLICATION_ENV production
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    Hope this helps someone!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •