Link to home
Start Free TrialLog in
Avatar of ssarkarnetip
ssarkarnetip

asked on

Can not get mod rewrite or mod alias to work in Linux Fedora9

I was creating a test web server.  Our production server runs on FreeBSD without any issues on apache 2.  I tried to start our web server.  Apache works fine, as well as cgi-bin and php.  However, I can not get mod_alias or mod_rewrite working at all.  The virtual hosts are working fine as well.  I see they are loaded in the php info page.  I also do not use any .htaceess files.
Avatar of HackneyCab
HackneyCab
Flag of United Kingdom of Great Britain and Northern Ireland image

The rewrite module is not compiled into Apache 2 by default.

If you compiled Apache yourself, you need to include "--enable-rewrite" in your call to the configure command.

To find out what modules are compiled into your Apache build, run

apachectl -l

(that's a lowercase L for Lima).

If you don't see mod_rewrite.c in the output, then your Apache build does not have the rewrite module you need to make RewriteRule work.
Oh, and you also want to see mod_alias.c in the output.
Avatar of ssarkarnetip
ssarkarnetip

ASKER

I am trying to run both mod_alias and mod_rewrite as a DSO. I am going to give you my httpd.conf.  It should run as a DSO theoretically.  I am uploading my httpd.conf file.  
httpd.txt
Have you checked (using apachectl -l) that mod_so.c is part of your Apache build? The mod_so module is included by default in Windows, but not necessarily in Linux.

Also, have you checked that the path /usr/lib/httpd/modules/mod_rewrite.so is correct (same for /usr/lib/httpd/modules/mod_alias.so) because if the modules are on your machine in a different location, LoadModule won't be able to find them.
Yes, I checked those.  Other dso modules such as php and cgi are running fine.  
In the httpd.conf file you shared, I can't see anywhere that a PHP module is loaded.

How are you testing the RewriteRule, and what result does Apache give you?

You have a lot of Redirect statements that seem to be using a full path, whereas you should be using a path beginning with a slash from the public web root. So instead of

Redirect 301 /var/www/html/Hmedicine/htdocs/shopping/symptom http://www.hmedicinetest.info/homeopathic/treatment

I believe you should be using

Redirect 301 /shopping/symptom http://www.hmedicinetest.info/homeopathic/treatment

(this assumes that the public web root of the hmedicine site is found on your machine at /var/www/html/Hmedicine/htdocs/)
I added the load module for php.   They say it is already loaded so it is skipping this module.  I used to have the redirect as you suggested but it did not work.  
When testing the rewrite module, it does not rewrite.  It does not give any errors.  It simply did not work.  
Do the rewrite statements work in the form you have them now?

What statement did you use to test the Rewrite directive?

Does this do anything (use on a test server only):

RewriteEngine On
RewriteRule ^/(.*)$ /$1?result=REWRITE-ON

If it works, a request to any page will redirect to the page, but add a query string of "?result=REWRITE-ON" to the end of the URL in the address bar of your browser.

If it doesn't work, what do you see in Apache's logs? On my box, these are found in /usr/local/apache2/logs but they may be in a different place on your rig.
Actually, thinking about it, that RewriteRule will loop infinitely, so change it to this:

RewriteEngine On
RewriteCond %{QUERY_STRING} !result=REWRITE-ON
RewriteRule ^/(.*)$ /$1?result=REWRITE-ON
This what the error logs say when I did that.  No errors were reported per se.  It did not do anything on the server.  This is a normal error for the page that I was on.

I went to www.hmedicinetest.info/homeopathic to see if anything happens.

[Thu Apr 15 15:29:49 2010] [error] [client 64.134.188.50] PHP Notice:  Undefined
 variable: s_description in /var/www/html/Hmedicine/htdocs/shopping/sidebar.php
on line 63, referer: http://www.hmedicinetest.info/homeopathic/
[Thu Apr 15 15:29:49 2010] [error] [client 64.134.188.50] PHP Notice:  Undefined
 index:  query in /var/www/html/Hmedicine/htdocs/homeopathic/search.php on line
33, referer: http://www.hmedicinetest.info/homeopathic/
[Thu Apr 15 15:29:49 2010] [error] [client 64.134.188.50] PHP Fatal error:  Call
 to undefined function mysql_connect() in /var/www/html/Hmedicine/htdocs/shoppin
g/connection.php on line 8, referer: http://www.hmedicinetest.info/homeopathic/

  These are some php errors which are okay.  The page is not redirecting or doing anything.
I'm afraid I don't know what else to suggest. If the modules are loaded, then the rewrite should have an effect. And if the modules aren't loaded, then I believe you should get a 500 status "internal server error" message when you try to request a page.

So I don't know where the problem lies.
SOLUTION
Avatar of Brad Howe
Brad Howe
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay,  I was getting a configuration error in the log files.  Also, the virtual host is not putting the log file where I specify.  It seems to be using the global variable in putting the log file.  It is putting it in the /etc/httpd/logs.  It should be putting it in the /var/www/html/Hmedicine/htdocs/ area.

This is the error log.
  [Thu Apr 15 17:19:05 2010] [notice] SIGHUP received.  Attempting to restart
[Thu Apr 15 17:19:05 2010] [warn] module php5_module is already loaded, skipping
[Thu Apr 15 17:19:05 2010] [notice] Digest: generating secret for digest authent
ication ...
[Thu Apr 15 17:19:05 2010] [notice] Digest: done
Configuration Failed
Configuration Failed
Configuration Failed

This is the custom log.
[Thu Apr 15 17:28:33 2010] [error] (2)No such file or directory: mod_rewrite:
 could not open RewriteLog file /logs/rewrite.log

Change the path of the RewriteLog directive to a path that suits you (and to which your Apache process will have permission to write).
I tried that.  When I put that code into the configuration. Apache dies.  It is giving an error that the configuration fails.  It is not starting at all.
That is because you have it written in your httpd.conf :/ .
I would suggest to start reading over it throughly.

EXCERPT FROM YOUR ATTACHMENT
------------------------------------------------------------------------------------
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/etc/httpd" will be interpreted by the
# server as "/etc/httpd/logs/foo.log".
#

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# Don't give away too much information about all the subcomponents
# we are running.  Comment out this line if you don't mind remote sites
# finding out what major optional modules you are running
ServerTokens OS

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation
# (available at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/etc/httpd/"
------------------------------------------------------------------------------------

In this case ServerRoot  = "/etc/httpd/" there for if you try to write to /logs/rewrite.log and the folder /logs doesn't exist then you will get that error. With that said, remove the / as it says above and try again.

Cheers,
Hades666
This is a test server.  Do you guys think that I should remove these rpms and start over with the installation of apache and php.  I know removing rpms is pretty straight forward.  I did this to install the packages.

yum install apache
yum install php

  Do you think there should be anything else that needs to be done with an installation?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My freebsd works prefectly in production.  The main difference between the two is the document root is in the same place on the virtual host.  Also the only dso module in the production version is php.  I am going to do a total emulation of my production httpd.conf and work from there but I do want to add mod_rewrite  and mod_alias as a DSO.
I am getting mod rewrite to work but not correctly.  I am going to double check my production httpd.conf to my test http.conf to make sure everything is correct.  I am also going to get rid of all the modules that are not needed in the default httpd.conf.  The Rewrite Log directive is working now.  I am definitely closer to getting everything working.
I get this error message in the rewrite.log.  It is obviously adding an extra / to the rewrite.  I am trying to figure out where that is happening.  It may be a global variable somewhere.  I actually have this httpd.conf file working in BSD.   A BSD conf file should work the same as linux conf file.  I have removed many of the unnecessary things in the default file.  Of course, I could have easily missed something.

 (2) rewrite '/index.html' -> '//index.html'
(2) explicitly forcing redirect with http://www.hmedicinetest.info//index.html
(1) escaping http://www.hmedicinetest.info//index.html for redirect
 (1) redirect to http://www.hmedicinetest.info//index.html [REDIRECT/301]
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial