Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
915 views
in Technique[技术] by (71.8m points)

linux - apache mod_rewrite not working with .htaccess file

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...