10

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??

Chris Fadu Uba
  • 133
  • 1
  • 1
  • 10
  • @anubhava Writing literally anything (except comments) in .htaccess causes 500 for me. :/ – Matt May 22 '21 at 12:30

4 Answers4

19

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
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I tried this, but it merely resulted in the same error. (Ubuntu 16.04. Django 1.10. WSGI.) – CoderGuy123 Jan 11 '17 at 09:06
  • But this worked. http://stackoverflow.com/a/18161348/3980197 Odd that I can enable it thru shell command but not by a setting. – CoderGuy123 Jan 11 '17 at 10:02
  • Don't forget to restart your apache server after making this change! `sudo apachectl restart` or whatever you command is. – lakewood Feb 21 '18 at 02:28
2

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.

ouzza
  • 41
  • 3
1

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

Menno van der Krift
  • 303
  • 1
  • 3
  • 15
1

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.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Mike
  • 11
  • 2