Currently I am using OSX Server (Yosemite) to host a bunch of PHP applications, some of which have a sub-directory under the websites document root for subdomains. Since updating to the Yosemite version of OSX Server, these subdomains have been throwing a 500 error with the error log referring to RewriteEngine not allowed here.
Investigating, I have confirmed that both the parent and subdomain sites have AllowOverride All configured, and .htaccess files are working on non-subdomain sites. Also, I have discovered that renaming or otherwise removing the .htaccess file from the parent directory causes the sub-domains to start working again.
/original_site_doc_root <- doc root for regular site
.htaccess
index.php
...
subdomain/ <- configured as a seperate site in osx server as a subdomain
.htaccess
index.php
...
Every bit of googling I do ends up referring to making sure mod_rewrite is installed and AllowOverride is configured properly.
My question is, how can I get Apache to stop throwing a 500 error on the sub-domain sites?
Edit
Here is the .htaccess file for the sub-domain that is causing me grief (with domains, directories and pages fuzzed to protect the innocent)
RewriteEngine On
Options +FollowSymlinks -Indexes
RewriteCond %{HTTP_HOST} ^www\.m\.somesite\.com$ [NC]
RewriteRule ^(.*)$ http://m.somesite.com/$1 [L,R=301]
RewriteBase /
# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
# enable PHP error logging
php_flag log_errors on
php_value error_log /some/fuzzed/dir
RewriteRule ^$ /index.php [L]
RewriteRule ^home$ /home.php [L]
RewriteRule ^some-page1$ /some-page1.php [L]
RewriteRule ^some-page2$ /some-page2.php [L]
RewriteRule ^some-page3/(.*)$ /some-page32.php [L]
RewriteRule ^some-page3(\/?)$ /some-page32.php [L]
RewriteRule ^some-page4/(.*)$ /some-page4.php [L]
RewriteRule ^some-page4(\/?)$ /some-page4.php [L]
RewriteRule ^some-page5/(.*)$ /some-page5.php [L]
RewriteRule ^some-page5(\/?)$ /some-page5.php [L]
RewriteRule ^some-page6/(.*)$ /some-page6.php [L]
RewriteRule ^some-page6(\/?)$ /some-page6.php [L]
The .htaccess for the parent directory/non-sub-domain-site is more or less similar, with the only real difference of relevance being the top 2 lines:
RewriteEngine On
Options +FollowSymlinks -Indexes -Multiviews
Just ran into this same problem (after recent update Apache2) and found a solution.
Assume your domain is example.com and the directory is /var/www/example/, and you had a subdomain called api.example.com with directory /var/www/example/api/.
Try to use the following:
<VirtualHost *:80>
ServerName api.example.com
DocumentRoot /var/www/example/api
<Directory /var/www/example/>
AllowOverride FileInfo Options
</Directory>
<Directory /var/www/example/api/>
Require all granted
Options +FollowSymLinks +MultiViews +ExecCGI -Indexes
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This should work!
Since updating to the Yosemite version of OSX Server, these subdomains have been throwing a 500 error with the error log referring to RewriteEngine not allowed here.
OS X 10.10 (Yosemite) ships with Apache 2.4, whereas earlier versions of OS X ship with Apache 2.2. An important difference between these versions, and which is probably causing you problems, is that AllowOverride defaults to All in Apache 2.2 and None in Apache 2.4. (See the Apache Docs) You are perhaps relying on this default behaviour.
I have confirmed that both the parent and subdomain sites have AllowOverride All configured
But where exactly are the AllowOverride All directives set? I assume the parent and subdomain sites are configured as separate Virtual Hosts. If AllowOverride All is only set in the parent domain's VirtualHost, for the "parent directory" (of the subdomain), then this will not been seen when you access the subdomain, which is an entirely separate VirtualHost. You will need to redeclare this in the subdomain's own (isolated) VirtualHost as well (as in #benck's answer).
Or, if you don't want the parent .htaccess file to be processed at all then explicitly set the following in the subdomain's VirtualHost:
<Directory /var/www/example/>
AllowOverride None
AllowOverrideList None
</Directory>
.htaccess files work along the filesystem path, regardless of the host being accessed.
Alternatively, if the main domain is configured in the main server config (ie. not in a VirtualHost container) then you shouldn't have this problem, as the VirtualHost will inherit the server's configuration.
Reference:
https://en.wikipedia.org/wiki/MacOS_Server#OS_X_10.10_(Yosemite_Server_4.0)
Related
Trying to fix this .htaccess, so it can work on a SSL apache server. Before it was hosted on another Linux server (http://) and was working without problems, but when uploading the files to another Linux server with apache and SSL (https://), it stopped working. The main function is to hide the .php extension...
HereĀ“s what I was using:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
Thanks for your help!
So, .htaccess files may not be allowed, and by default on many systems they are not allowed. To see if .htaccess is allowed, make this your .htaccess:
BREAK IT!
That should be the only contents in your .htaccess. Attempt to load any page on your website, and if .htaccess usage is enabled, you would see "Internal Server Error" or possibly some other error, but you would not see your actual page.
If you do see the error, that's actually good and means .htaccess usage is enabled. If you don't see the error, it's likely that you will have to find your Apache .conf file and inside look for the line(s):
AllowOverride None
Change that to:
AllowOverride All
If after doing that you still can't use .htaccess, then there may be other apache related files that have "AllowOverride None". On that comes to mind is your virtual host file, and on my system that is located at /etc/apache2/sites-available/.
If you still have problems, check this out:
https://docs.bolt.cm/3.3/howto/making-sure-htaccess-works
Solution is for the issue, need to change in apache2.conf file after that it will works,
Change this file /etc/apache2/apache2.conf
update it same
OLD:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
New Updated Code:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I had a similar problem. Apache 2.4.23 with .htaccess error 404 set up.
Using it with HTTP works fine; access it with HTTPS didn't work.
I seted AllowOverride All in the http.conf and error 404 wors well.
I am not an apache guru. But I want to configure my server for mass virtual hosting using CakePHP. The idea is that we will be able to easily set up multiple versions of the same application based on directory location:
production.domain.com
testv1.domain.com
etc...
So I know I have mod_vhost_alias working just fine. I have a basic directory set up where I have added a test index.html file (/var/www/htdocs/cake/test/webroot). When I point my browser to the location (test.domain.com), the index.html is displayed in the browser. My vhost is configured to pull %1 from the URL to know what directory to point to:
VirtualDocumentRoot /var/www/htdocs/cake/%1/webroot
But when I point my browser to the cake application, I get a page not found error. I suspect it has something to do with the mod_rewrite in the .htaccess file. Here are the full configs for both:
mod_vhost_alias (in .conf file)
<VirtualHost *:80>
ServerAlias *
UseCanonicalName Off
VirtualDocumentRoot /var/www/htdocs/cake/%1/webroot
<Directory /var/www/htdocs/cake/%1/webroot>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.htaccess (in webroot - default as it comes from CakePHP)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Any ideas how to get them to work together?
Turns out all it needed was:
DirectoryIndex index.html index.php
I am not able to switch to pretty permalinks in WAMP. Changing to any form other than default gives 404 error.
I have switched on the rewrite_module in Apache. I Googled the problem and found that following changes should be made to httpd.conf file. My httpd.conf file stands as
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
I also checked that the .htaccess file is getting created. It reads as
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /vit%20web/events/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /vit%20web/events/index.php [L]
</IfModule>
# END WordPress
All you need to do is turn on the mod_rewrite in the wamp settings tab.
Click Wamp -> Apache -> Apache Modules -> rewrite_module
If you select that then turn on %postname% it should work
Did you reboot Apache after editing httpd.conf?
A bulletproof check for mod_rewrite is to remove the <IfModule>...</IfModule> tags and try running WordPress - if you get a 500 Server Error, mod_rewrite isn't installed.
Also I would recommend changing <Directory /> to <Directory "C:/path/to/server/root"> (note the forward slashes too, even on Windows).
And the deny order should be switched if you're only on a development server;
Order allow,deny
Allow from all
The problem may be:
Whenever you have permalinks in subfolder of your main www folder (i.e.
RewriteBase /subdirectory/
you may need to have a .htaccess file in your main c:\wamp\www folder too.
I am trying to redirect /folder to / using .htaccess but all am I getting is the Apache HTTP Server Test Page.
My root directory looks like this:
/
.htaccess
-/folder
-/folder2
-/folder3
My .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule ^(.*)$ folder/$1 [L]
What am I doing wrong? I checked my httpd.conf (I'm running Centos 5.3) and the mod_rewrite library is being loaded. As a side note, my server is not a www server, its simply a virtual machine so its hostname is centosvm.
Addition: I have found that the mod_rewrite module is loaded, but none of my .htaccess redirects seem to be working.
Addition: My httpd.conf directory directive looks like:
<Directory />
Options FollowSymLinks
#AllowOverride None
</Directory>
What does you AllowOverride say? (see: http://httpd.apache.org/docs/2.0/howto/htaccess.html)
And that would bring us to requiring this in (virtual)host/directory settings:
AllowOverride FileInfo
I am building a web application with Zend Framework, and I need to point my app to the "public" folder of the application:
So basically when I call http://localhost/myapp
it should display http://localhost/myapp/public/
I created a virtual host file called myapp into /etc/apache2/sites-available/:
<VirtualHost *:80>
DocumentRoot /var/www/myapp/public/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/myapp/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
But it doesn't work. When I call http://localhost/myapp, it displays the directory structure of the app, and when I click on the "public" folder, then it displays what I want to be displayed by default...
I never configured vhosts before and that's as far as I got with the tutorials about it.
In your first listing, you had a different value for the Directory tag, leaving off 'public' altogether. There was also a trailing slash after 'public' in the DocRoot value, but removed on your second attempt. Not sure that made a difference, but I believe it's recommended that you don't include trailing slashes.
Also, just wondering...are you running this on a local machine? I had trouble with Skype wanting to use port 80 if I started running that before my apache server. Skype will use a different port if 80 is already used. If not Skype, there may be another app that's using port 80 and interfering. That could be why you had success on another port.
Ok I found a way somehow... I don't think it's necessary the right/best way but...
in httpd.conf (in apache2 folder):
Listen 10089
<VirtualHost *:10089>
DocumentRoot "/var/www/myapp/public"
<Directory "/var/www/myapp/public">
Order allow,deny
Allow from all
AllowOverride all
</Directory>
</VirtualHost>
My app is now accessible via localhost:10089
After enabling the rewrite mod in apache, I added the necessary .htaccess, one at the root of my app, redirecting everything to index.php (Zend framework support friendly url navigation and works that way):
RewriteEngine on
RewriteRule .* index.php
and a second .htaccess file inside my public folder to allow people to access .jpg,.ico,etc files and not being redirected to index for everything:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Hope this will help some!