Forum Moderators: phranque

Message Too Old, No Replies

basic problems with mod_rewrite, including no logging

mod_rewrite loaded, but not working and not logging?

         

walter_80

10:18 pm on Mar 25, 2006 (gmt 0)

10+ Year Member



Hi, I am sorry asking about somthing that must be pretty basic. However, I am at my wits end with this.

I have the following information in /etc/http/conf.d/mod-rewrite.conf:

RewriteEngine On
RewriteLog "/var/log/httpd/rewrite_engine_log"
RewriteLogLevel 3
RewriteRule ^alice.html$ bob.html

I know it is being loaded by httpd since it picks up on syntax errors and the log file is being created.

I have the following in my /etc/http/conf/httpd.conf:

<Directory "/home/*/html">
Options FollowSymLinks
AllowOverride FileInfo
Allow from all
Order deny,allow
</Directory>

I have read that I need FollowSymLinks and FileInfo?

I made the files alice.html and bob.html and put them in my [host.com...] directory. When I load alice.html it still gives me alice.html.

The most bothersome thing is that I don't get anything in my log file. I have tried all kinds of log levels. The file remains empty. I have also tried using the .htaccess approach with no luck.

My real goal is to force https for a couple of urls, but I clearly cannot get past step 1 here. I apologize in advance if I am doing something stupid or if this is in a FAQ somewhere. Any suggestions would be greatly appreciated.

thanks, mark

jdMorgan

2:24 am on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At the server config level (httpd.conf as opposed to .htaccess), the syntax would be:

RewriteRule ^/alice.html$ /bob.html [L]

Jim

walter_80

3:45 am on Mar 26, 2006 (gmt 0)

10+ Year Member



Jim, the changed RewriteRule did not make a difference. I am not sure if it helps, but I am using Redhat Enterprise Linux with only a few modifications to httpd.conf. I turned off SELinux at one point to see if it was interfering in some way. It didn't make a difference so it is back on.

The fact that nothing is being logged is bothering me. At a debugging level I would have thought that I would see things like "RewriteEngine is on" and "Entering RewriteRule #*$!", etc. Is it possible that there are problems with permissions?

thanks, mark

jdMorgan

3:50 am on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that the RewriteRules should be within a Server container -- I doubt they'll do anything in mod-rewrite.conf, as a matter of fact, I've never used that file.

Jim

walter_80

8:22 am on Mar 26, 2006 (gmt 0)

10+ Year Member



Jim, thanks for your responses. I got the test case working (and logging) with the following (note that I moved everything to /var/www/html, though that was not necessary):

/etc/http/conf/httpd.conf:
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride FileInfo AuthConfig
Allow from all
Order allow,deny
</Directory>

/etc/http/conf.d/mod-rewrite.conf:
RewriteLog "/var/log/httpd/rewrite_engine_log"
RewriteLogLevel 3

/var/www/html/testdir/.htaccess:
RewriteEngine On
RewriteRule ^alice.html$ bob.html

Now I am trying to do what I orginally set out to do, to force my phpMyAdmin install to load in https.

I have an alias set:
Alias /mysql "/var/www/phpMyAdmin-2.8.0.2"

Then my .htaccess file in /var/www/phpMyAdmin-2.8.0.2 is as follows:

RewriteEngine On
RewriteCond %{HTTPS}!=on
RewriteRule ^/mysql/(.*) [%{SERVER_NAME}...] [R,L]

This is unfortunately not working. The logs are showing things like the following:

IPADDR - walter [26/Mar/2006:03:34:15 --0500] [oak.eng.ohio-state.edu/sid#8f96780][rid#9155188/initial] (1) [per-dir /var/www/phpMyAdmin-2.8.0.2/] pass through /var/www/phpMyAdmin-2.8.0.2/

This seems to indicate that it does not deal with the alias properly? Any suggestions?

thanks, mark

jdMorgan

3:18 pm on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please note the difference between a rule in a config file and the same rule in an .htaccess file:

config:


RewriteRule [b]^/my[/b]sql/(.*) https://%{SERVER_NAME}/mysql/$1 [R,L]

.htaccess


RewriteRule [b]^my[/b]sql/(.*) https://%{SERVER_NAME}/mysql/$1 [R,L]

The requested local-URL-path 'seen' by RewriteRule in a per-directory (.htaccess) context is localized, i.e. stripped of the directory prefix used to get to this .htaccess file's directory -- in this case, "/".

Jim

walter_80

5:19 am on Mar 27, 2006 (gmt 0)

10+ Year Member



Jim, once again, thanks for your help. I have a working .htaccess file now. I had tried with and without the "/". I am sorry that you have to tell people (including me) about the difference between .htaccess and httpd.conf all the time. My realy problem was in the location of my .httaccess file. I had actually put it in the "mysql" directory ... duhhh. When I tried ^(.*) from in the actual directory, everything worked, but then I had the trailing slash problem. I got around that by moving it up on level.

Here is what I am now using. I could have multiple .htaccess files, but I have one in /var/www/ with the following information:

RewriteEngine On
RewriteCond %{SERVER_PORT}!443
RewriteRule ^html/SiteBar/(.*)$ [%{SERVER_NAME}...] [R,L]

RewriteCond %{SERVER_PORT}!443
RewriteRule ^phpMyAdmin-2.8.0.2/(.*)$ [%{SERVER_NAME}...] [R,L]

RewriteCond %{SERVER_PORT}!443
RewriteRule ^html/egroupware/(.*)$ [%{SERVER_NAME}...] [R,L]

RewriteCond %{SERVER_PORT}!443
RewriteRule ^html/gallery/(.*)$ [%{SERVER_NAME}...] [R,L]

As you can see, I had some trouble with the mysql rule. I tried using RewriteBase, to take care of the alias, but it didn't work. This seemed like a reasonable solution.

Thanks again for you generous help. regards, mark

jdMorgan

2:23 pm on Mar 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could compress that to two rules:

RewriteEngine on
#
RewriteCond %{SERVER_PORT} !443
RewriteRule ^html/(SiteBar¦egroupware¦gallery)/(.*)$ https://%{SERVER_NAME}/$1/$2 [R,L]
#
RewriteCond %{SERVER_PORT} !443
RewriteRule ^phpMyAdmin-2.8.0.2/(.*)$ https://%{SERVER_NAME}/mysql/$1 [R,L]

Are you sure you want a 302 redirect? Use 302 only if this change is temporary AND you DO NOT want search engines to show the new URL in search results. Otherwise, use the [R=301,L] flag on your rules.

Change all broken pipe "¦" characters to solid pipes before use; Posting on this board modifies them.

Jim

walter_80

4:44 pm on Mar 27, 2006 (gmt 0)

10+ Year Member



Thanks Jim! I have followed your suggestion about R=301. Your use of regex also makes the rule much cleaner. I have learned a lot! M<