Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

500 internal error with RewriteEngine on .htaccess on localhost with wamp

Tags:

.htaccess

I'm having a problem with a script. It doen't works with a htaccess file that is needed to work. Here's what the htaccess contains. I'm trying to install it on a wamp localhost. The code is:

#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
#RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

Options All -Indexes

If I remove this it works:

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
#RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

But this way the script loads but every page show error 404. Is there a way to resolve this problem??

like image 505
Chris Fadu Uba Avatar asked Nov 01 '13 00:11

Chris Fadu Uba


People also ask

Why do I keep getting error 500?

The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request. This error is usually returned by the server when no other error code is suitable.


4 Answers

This is one solution that solved the issue for me. Rewrite module was always enabled, used in IfModule rewrite_module, permissions were granted and .htaccess contents were fine, yet it still was 500 error trying to use rewrite module.

In httpd.conf by default:

This is a source of a 500 error if you try to use rewrite in .htaccess in some sub directory.

` 
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#

    <Directory />
        AllowOverride none
        Require all denied
    </Directory>
`    

So one may want to use .htaccess with rewrite module in a specific directory. You would add a <directory> block for that directory. If one copies and pastes the directory block, you need to make sure the intent of the block you copy is correct for the directory you want to apply it to.

So for my intent this block, causes a 403 error, but does get rid of the 500 error.

<Directory "c:/Apache24/htdocs/store">
    AllowOverride All
    Options None
    Require all granted
</Directory>


Changing to this solved the issue:

<Directory "c:/Apache24/htdocs/store">
    AllowOverride All
    Require all granted
</Directory>

I suppose this is why the issue is commonly seen, but rarely solved in these threads. If I simply copied a different block, typed my own block, or had any understanding of what I was doing, this wouldn't have been an issue.

I can't say this solves everybody's issue, but I hate when people solve-and-run w/o enlightening the rest of us. So for those that did my mistake, this is the answer.

like image 155
Mike Avatar answered Oct 18 '22 13:10

Mike


It looks like you don't have the rewrite modules loaded. Find your httpd.conf file and make sure this line (or something similar) is uncommented:

LoadModule rewrite_module modules/mod_rewrite.so
like image 41
Jon Lin Avatar answered Oct 18 '22 14:10

Jon Lin


Check that you have the the apache rewrite module loaded.

go to wamp_manager -> apache -> modules and look for rewrite_module in the list.

If it does not have a TICK beside it click it. Apache will be bounced ( stop, start ). Try again.

The rewite engine will not work without the required module loaded.

like image 21
ouzza Avatar answered Oct 18 '22 12:10

ouzza


I had the same problem. To un-comment the line, remove the # in front of the line LoadModule rewrite_module modules/mod_rewrite.so

Worked for me in Wamp.

Directory of the httpd.conf file: C:\wamp\bin\apache\apache2.4.9\conf

like image 37
Menno van der Krift Avatar answered Oct 18 '22 13:10

Menno van der Krift