.htaccess: RewriteEngine not allowed here - .htaccess

I uploaded the .htaccess to the server and received an Error 500 (Internal Server Error).
And in the error log I had the following error:
.../.htaccess: RewriteEngine not allowed here
But mod_rewrite.so is enabled.
So, do I need to change
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
to
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
in the /etc/httpd/conf/httpd.conf file?
Or could it be something else? The .htaccess file should be okay, because it works perfectly fine on my localhost. I just don't want to screw anything up.
Here's part of my .htaccess file:
Options All -Indexes
Options +FollowSymLinks
RewriteEngine On

minimum configuration for your .htaccess to work:
AllowOverride FileInfo Options
allowing all configuration will work as well:
AllowOverride All

Let's say your DOCUMENT_ROOT is /home/foo/web then have this config in your httpd.conf file:
<Directory "/home/foo/web">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This should take care of RewriteEngine is not allowed error you're getting.

Just an idea, this happened to me, and I've lost a lot of time trying to solve it.
If you have a directory like d:/web/my-sites/some-site/
And you place the .htaccess on d:/web/my-sites/some-site/.htaccess (where it supposed to be).
If you have ANY .htaccess files before this directory, Apache reads that files, and blocks the execution of the entire path, producing an internal server error.
I.E.: You have d:/web/my-sites/.htaccess

In httpd version 2.4 (2.4.3 and 2.4.4), take a look at /etc/httpd/conf.d/wordpress.conf
There is one entry for:
....
Change:
"AllowOverride Options"
to
"AllowOverride All"
in wordpress.conf also in addition to changing httpd.conf. Restart the http server before the changes will take effect.

Also, just make sure you are editing the correct config file. I had created a file under /etc/apache2/users/USERNAME.conf but was editing /etc/apache2/httpd.conf.
Removing the USERNAME.conf file worked.

Try to change username.conf file on Mac under /etc/apache2/users/username.conf to
<Directory "/Users/akyoo/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
My .htaccess file looks like this
#Allow from all
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
This works fine for me.
Solution for Ubuntu users

I was getting this type of error from the Google Cloud instance after checking the logs from the /var/log/apache2/error.log
.htaccess: RewriteEngine not allowed here
To get rid of the above error & 500 Internal Server Error, follow these simple steps
sudo nano /etc/apache2/apache2.conf
Then add these snippets of lines
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After you’ve made that change, make sure to restart the server:
sudo service apache2 restart
This worked for me in getting rid of 500 Internal Server Error hosted on Google Cloud instance

you could use something like this in your .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|html|test)
RewriteRule ^(.*)$ /index.php/$1 [L]
this code simply means, that anything not pointing to index.php or html or test should be directed to index.php!
Hope this is helpful!

Related

Simple URL rewriting fails

I have a very simple aim: Rewrite the URLs of my PHP app such that localhost/slim_demo/archive is interpreted as localhost/slim_demo/index.php/archive by the system but the user sees the former. EDIT: The system is behaving as if no rewriting is taking place. The latter version of the URL returns data, but the former throws a Not Found error.
I used the following .htaccess file, but it's not happening (by the way, as the second line says, uncommenting it rejects all requests, which shows that .htaccess is alive and kicking):
Options +FollowSymLinks -MultiViews -Indexes
#deny from 127.0.0.1 #Uncomment to prove that .htacess is working
RewriteEngine On
RewriteRule ^slim_demo/(.*)$ slim_demo/index.php/$1 [NC,L]
And here's the relevant section from my apache2.conf:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /media/common/htdocs>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I also did a2enmod rewrite and service apache2 restart. Frustrated, I also added this to my sites-available and did a restart:
<Directory /media/common/htdocs/>
Options +FollowSymLinks -Indexes
AllowOverride All
</Directory>
Not sure what else I need to do!
So if this .htaccess file is in the slim_demo directory, your RewriteRule never matches :
In Directory and htaccess context, the Pattern will initially be
matched against the filesystem path, after removing the prefix that
led the server to the current RewriteRule
(The pattern is in your case the ^slim_demo/(.*)$ part).
This means that when you try to get the URL localhost/slim_demo/archive the slim_demo part is removed, and your rule never can match.
So you need:
RewriteRule ^(.*)$ index.php/$1
but this will bring you in an infinite loop and a 500 error. You must trigger this rule only if the REQUEST_URI does not have the index.php.
All together becomes:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(?!/slim_demo/index\.php).*$
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

Laravel 4 routing not working due to .htaccess file?

I'm writing my steps and findings here so you can see what I've tried and what results I got. Any advice would be welcomed. I followed the comments in this answer.
I'm running Laravel 4, using XAMMP version 1.8.2 with PHP 5.4.19 and Apache 2.4.4 on a Windows 7 machine and I'm simply still trying to get a local instance up and running.
In my case: http://localhost/sos/sos_public/ is my main screen and that works, but when I try to get to http://localhost/sos/sos_public/signup I get this error: Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException which has been talked about a lot on the net, and then I found GaryJ stating that it might be an .htaccess issue, so I did what he suggested.
My /app/routes.php file looks like this (I've tried this with a / in front of signup too):
Route::get('signup', function()
{
return 'hello!';
});
Route::get('/', function()
{
return View::make('hello');
});
First:
Just for a laugh, see if /index.php/hello works. If so, then it's a .htaccess problem.
http://localhost/sos/sos_public/index.php/signup worked perfectly fine. So it's an .htaccess problem.
My .htaccess file looked like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And:
if you're running Apache 2.4, note the changes since previous
versions, regarding Require all granted and AllowOverride all within a
<Directory />...</Directory> block on your virtual host.
I added this in my httpd.conf file as suggested by Dalton Gore - got the Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException error (changed this directory path to /SOS/sos_public and C:/xammp/htdocs/SOS/sos_public/ and C:/xammp/htdocs/SOS/sos_public - same results):
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory /SOS/sos_public>
AllowOverride all
Require all granted
</Directory>
Next:
Check if anything in .htaccess is working
I added dsjkdsfghk to my .htaccess file and immediately got an error, so I know my .htaccess file is being used.
Then:
Try removing the IfModule conditional. As you've got access to the
host / vhost, you can soon enable that module if it's not - so it
doesn't need be checked on every request. Equally, try moving it out
of .htaccess, and into a <Directory />...</Directory> block in your
vhost - if you've got nothing else in your .htaccess it can then be
deleted as well.
Having an empty .htaccess file caused a 404 error in my browser for http://localhost/sos/sos_public/signup (http://localhost/sos/sos_public/ still worked).
Removing the .htaccess file from C:\xampp\htdocs\SOS\sos_public\ had the same results.
Then:
Try: <VirtualHost *:80> DocumentRoot
"/Users/amiterandole/Sites/laravelbackbone/public" ServerName
laravelbackbone.dev <Directory /> AllowOverride all Require all
granted </Directory> <IfModule mod_rewrite.c> Options -MultiViews
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^
index.php [L] </IfModule> </VirtualHost>
I did that and just like Amit,
I emptied out my htaccess file and tried the above and now nothing
seems to work.
Except where his laravelbackbone.dev pointed to his Sites folder root, I just got an Error 400 - Bad request on both http://localhost/sos/sos_public/ and http://localhost/sos/sos_public/signup when I ran them in my browser.
My httpd-vhosts.conf file looked like this:
<VirtualHost *:80>
DocumentRoot "C:/xammp/htdocs/SOS/sos_public"
ServerName sos.dev
<Directory />
AllowOverride all
Require all granted
</Directory>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</VirtualHost>
and in my .hosts file I obviously had:
127.0.0.1 sos.dev
Lastly:
You've definitely got the conf/extra/httpd-vhosts.conf file be
included (uncommented) within the main httpd.conf?
I have this uncommented - yes.
Another link I tried but to no avail: https://stackoverflow.com/a/17778222/956975 and http://www.epigroove.com/blog/laravel-routes-not-working-make-sure-htaccess-is-working
What should I change where?
What am I missing?
Your ServerName is
sos.dev
And apache take this in consideration, you you must access your routes using:
http://sos.dev/
And NOT
http://localhost/
It might be the error of not enabling rewrite Engine in apache2
In linux,
sudo a2enmod rewrite
sudo systemctl restart apache2
In windows,
You should find httpd.conf file if it's not available in your apache look for apache2.conf file is another name for httpd.conf and enable the rewrite module for more info or here see how to do above-said procedure in this link
Lost httpd.conf file located apache

Hiding "index.php" at url in "YII" when using "https" does not work

here i am stuck with a small problem. I have a site built in Yii framework. It runs without any problem with http protocol (the index.php in url is hidden and all urls work fine). I have hosted this in amazon ec2 services. i have the following lines in my .htaccess file
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
but when i use https to browse the site (note: i have it all configured) , the home page loads normally. but the other urls does not work and requires /index.php/ to be added. what am i missing here?
dying for answers.
thanks in advance.
To get mod_rewrite working not only mod_rewrite must be installed, but also check in the Apache directory config (/etc/apache2/sites-enabled/000-default on Ubuntu installed via apt-get) if the rule "AllowOverride None" exists in your project's directory config. If so, change it to "AllowOverride All".
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
**AllowOverride All**
mod_rewrite can be installed by remove comment from this line
#LoadModule rewrite_module modules/mod_rewrite.so
After a long search for the .htaccess configurations, main file configurations, the solution was found in /etc/apache2/sites-enabled directory , in the default-ssl file. (thanks to Hemc's answer)
this is what i did. this may help some others:
first move to the apache's sites-enabled directory
cd /etc/apache2/sites-enabled
then open default-ssl file
sudo vi default-ssl
then change AllowOverride None to AllowOverride All
Actually this is in the top of my file and it works fine .ie. my index.php is properly hidden and urls work fine :)
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
And finally after saving and quitting, dont forget to restart your apache
sudo service apache2 restart
thanks

How to get .htaccess files working with Apache VirtualHost

My problem is that my .htaccess file on my local server is not being read. The settings in the VirtualHost file seem to always take precedence.
I have tried the following:
Enabled mod_rewrite
Changed the AllowOverride to All but this causes a HTTP Error 500 Internal server error. I have tried it with various options but it always causes a 500 error.
I am using a VirtualHost file on Ubuntu which looks like the following:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /web/website
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /web/website>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
In my .htaccess file under /web/website I have the following rules (which are not being read):
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit
RewriteRule ^(.*)$ ogtags.php?$1 [L,QSA]
ErrorDocument 404 /404
ErrorDocument 401 /401
One thing I tried which did work was appending these rules directly into the VirtualHost file, but I would like my .htaccess file to work! Is that such a big ask? :(
Edit: So I looked in my apache error.log and it says Invalid command 'Action', perhaps misspelled or defined by a module not included in the server configuration referring to my .htaccess file. There doesn't seem to be a module called Action which I can enable. Any ideas?
Edit 2: I noticed that my httpd.conf file is blank. Should this matter since I am using VirtualHost files?
After looking at my apache error.log I realised I just had to enable the Apache actions module:
sudo a2enmod actions
And no more 500 Internal Server Errors!
Hope this helps somebody down the line :)
You miss the RewriteBase / directive
Add it after the RewriteEngine directive :
RewriteEngine On
RewriteBase /

How to get MAMP to read .htaccess files

I am trying to get the .htaccess working in MAMP. The content of the .htaccess is a simple redirect line, but the entire .htaccess file seems to have no effect, even when I change it to contain invalid data.
Is there any settings within MAMP I need to change to enable .htaccess files?
In httpd.conf on /Applications/MAMP/conf/apache, find:
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
Replace None with All.
Restart MAMP servers.
Go to httpd.conf on /Applications/MAMP/conf/apache and see if the LoadModule rewrite_module modules/mod_rewrite.so line is un-commented (without the # at the beginning)
and change these
from ...
<VirtualHost *:80>
ServerName ...
DocumentRoot /....
</VirtualHost>
To this:
<VirtualHost *:80>
ServerAdmin ...
ServerName ...
DocumentRoot ...
<Directory ...>
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory ...>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I'm using MAMP (downloaded today) and had this problem also. The issue is with this version of the MAMP stack's default httpd.conf directive around line 370. Look at httpd.conf down at around line 370 and you will find:
<Directory "/Applications/MAMP/bin/mamp">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
You need to change: AllowOverride None
To: AllowOverride All
If you have MAMP PRO you can set up a host like mysite.local, then add some options from the 'Advanced' panel in the main window. Just switch on the options 'Indexes' and 'MultiViews'. 'Includes' and 'FollowSymLinks' should already be checked.
The problem I was having with the rewrite is that some .htaccess files for Codeigniter, etc come with
RewriteBase /
Which doesn't seem to work in MAMP...at least for me.
I have MAMP v 6.6.2 (year 2022), and I was trying to make working php friendly URLs on my localhost Apache, by adding '.htaccess' file to my website root directory ("localhost/mywebsite/.htaccess"):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]
Which didn't work. But I tested it on cPanel hosting on a real domain and it worked fine.
So I have tried to change httpd.conf with these advises:
https://stackoverflow.com/a/21411933/3936149 - didn't help
https://stackoverflow.com/a/7670598/3936149 - didn't help
https://stackoverflow.com/a/19204983/3936149 - didn't help
In the end I came up to an advise:
https://stackoverflow.com/a/16106140/3936149 - and it worked!
I simply commented out the second line of the code in my '.htaccess' (located at "localhost/mywebsite/.htaccess") file and that's it:
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]
After it started to work I reverted all the changes in httpd.conf file, I have done above, and it was still working.

Resources