htaccess causing server error 500
I have a Zend Framework application with a .htaccess
file in the root directory, directing all traffic to the /public
directory, where index.php
resides.
This is the contents of the .htaccess
:
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/(upload|img|js|css|less)/.*$
RewriteCond %{DOCUMENT_ROOT}/public/upload%{REQUEST_URI} -f
RewriteRule ^(.+\.(jpg|png|mp3))$ /public/upload%{REQUEST_URI} [NC,L]
;RewriteCond %{REQUEST_URI} !^/public/.*$
;RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
As you can see, there are two commented out lines.
The section, supposedly directing traffic to /public
, and which works on my local servers and my shared host, seems to fail miserably on my client's server.
So, with the two lines commented out, when I type the site's address in the browser, I get a directory listing. When I append /public
to the address, I'm taken to /public/index.php
, as expected, but since the request wasn't redirected correctly, neither are the ones to the JS and CSS files.
When I uncomment the lines, I get a 500 internal server error (index.php
is not reached at all).
The other rewrites work correctly (at least as far as I can tell).
Any ideas why this would happen and how to correct this?
Thank开发者_如何学JAVAs in advance.
Save yourself a lot of grief and do the following:
- Set the document root to the
public
directory. - Set the rewrite rules in the VirtualHost entry or use the standard Zend Framework rewrite rules in a
.htaccess
file in thepublic
directory.
Ok, given your shared hosting constraints, try this one out...
- Place all the
public
files into your document root including the.htaccess
file mentioned in step #2 above - Place the rest of the folders (ie
application
,library
) anywhere in the filesystem, preferably outside the web document root. An example might be/home/user/apps/my-app-name/
Modify the
index.php
file with the newAPPLICATION_PATH
, eg// Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', 'home/user/apps/my-app-name/application');
Now everything should "just work" and your site won't be accessed with the word "public" in the URL.
精彩评论