5

OK, I've been having some issues with aws or something, such that I cannot seem to get mod_rewrite to work.

Just for testing purposes I've done the following:

1 used aws console to deploy fresh ami 64 bit instance from wizard

2 yum installed apache

3 edited /etc/httpd/conf/httpd.conf: so that

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

looks like

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

4 made sure that

LoadModule rewrite_module modules/mod_rewrite.so

is in the file and uncommented.

5 restarted apache:

 sudo /sbin/service httpd restart

6 created two new files:

/var/www/html/test1.html

contains:

this is test1!

/var/www/html/test2.html

contains:

this is test2!

7 created file:

/var/www/html/.htaccess

contains (IN TOTAL):

RewriteEngine on
RewriteRule ^test1\.html$ test2.html [L]

8 went to:

http://[my aws server]/test1.html

Am getting "this is test1!"

I am doing something wrong here, but for the life of me I have no idea what. Any help is greatly appreciated...

EDIT: I added nonsense chars/numbers to the beginning of my .htaccess file, and restarted apache (not 100% sure that is needed, but what the hey...), and nothing happened. In other words, I expected that going to the url [aws server]/test1.html would result in some kind of error, but it did not. I suspect apache is not even reading the .htaccess file.

EDIT: I added the following to my httpd.conf file:

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

The file is created when I restart apache, but nothing ever goes in there when I go to either page I've set up. I'm failing to do something very, very basic here, but I'm not sure what...

2
  • Note that I know there are a ton of issues like this one on SO. I've been working my way through them trying to find one that fixes my issue. But if anyone can point me to a good or complete mod_rewrite troubleshooting issue, I would appreciate it!
    – snuggles
    Jul 26, 2013 at 21:54
  • Just to make the solution more obvious, since it's contained in my comment below: the httpd.conf file already had a section for /var/www/html, which had 'AllowOverride None' in it. Instead of changing that, I was trying to add a second one, which was being ignored. Lesson learned: first check to make sure you aren't duplicating an already-existing section! :)
    – snuggles
    May 6, 2015 at 14:43

3 Answers 3

15

Not sure if this is the cause of your problems, but you shouldn't mess with the

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

line, and it should be something like:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Deny from all
</Directory>

You should add the directory of your document root as a different container:

<Directory /var/www/html/>
    Options FollowSymLinks
    AllowOverride All
    Allow from all
</Directory>
3
  • Thanks Jon. I had seen that what you outlined is the "correct" way, I just wanted to present the simplest possible test. I re-set the Directory options back to the default, and added the code you outlined just below that to my httpd.conf file. Since my docroot by default is the directory you specified already, I saved and restarted apache. Unfortunately, that did not seem to solve the problem :(
    – snuggles
    Jul 26, 2013 at 20:36
  • @snuggles The only other thing I can think of is check your configuration for AccessFileName, it should be set to .htaccess, but if it's something else then your .htaccess file will be completely ignored. Also make sure .htaccess file is readable by the apache process.
    – Jon Lin
    Jul 26, 2013 at 21:55
  • 1
    You lead me in the right direction: the httpd.conf file already had a section for /var/www/html, which had 'AllowOverride None' in it. I just frankly did not think to look for a section already in the conf file, I assumed it just came with the default. Jeeeeez. I set 'AllowOverride All' and everything's working. Thanks Jon!
    – snuggles
    Jul 26, 2013 at 22:51
4

Took me a while to find this but in some installs Apache will use multiple config files.

Look in "/etc/apache2/sites-enabled/000-default" and check that AllowOveride is set to All

1
  • This got me really shouldn't have .. Thanks !
    – Pogrindis
    Jul 22, 2014 at 22:46
2

Try it. This work for me. The first, you need to make sure the .htaccess file put in correct directory. For this, you go to sites-enabled folder and check which the .conf files are enabled.

cd /etc/apache2/sites-enabled
ls

Ex: 000-default.conf

Then, goto sites-available folder to edit that .conf file.

cd ../sites-available
sudo gedit 000-default.conf

Find to DocumentRoot and check directory again. If you put .htaccess file in /var/www/html/.htaccess so this line look like this:

DocumentRoot /var/www/html/

The second, You need modify <Directory> block look like this.

    <Directory /var/www/html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    # This directive allows us to have apache2's default start page
            # in /apache2-default/, but still have / go to the right place
            #RedirectMatch ^/$ /apache2-default/
    </Directory>

Finally, you save file and restart apache

service apache2 restart

Hope this help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.