Solved

Apache MOD_REWRITE trouble

Posted on 2007-03-27
14
173 Views
Last Modified: 2010-05-18
I am trying to set up mod_rewrite. in my httpd.conf file i have set it to load the mod_rewrite module, but when i try to set rewrite rules, it isn't working. here is my code:

RewriteEngine on
RewriteRule ^/error/([0-9]+)$ /error-pages/$1.php


I don't get errors, but when i go to "/error/404" to test it, it tells me the page isnt found and DOESNT show my custom error page.
0
Comment
Question by:Oscurochu
  • 7
  • 7
14 Comments
 
LVL 27

Expert Comment

by:Nopius
ID: 18804339
If you are using rewrite engine in .htaccess, then tty these rules (in top htdocs directory .htaccess):

RewriteEngine On
RewriteBase /
RewriteRule ^error/([0-9]+)$ error-pages/$1.php

0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18804357
im not doing this in htaccess, im doing it in httpd.conf

do i have to use .htaccess?
0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18804376
i tried creating an .htacess file with the rewrite rules and it still isn't working
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18804506
For directory where .htacess resides please define AllowOverride option.

<Directory /...>
...
AllowOverride All
...
</Directory>

It works on my apache and I tested it before posting (but used 404.txt instead of 404.php).
It might be you placed your .htaccess into incorrect directory (not into the domain top /).
0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18804609
i have "AllowOveride All" set
the .htaccess file IS in the top level directory
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18804678
Ok, let's start a debug session :-)

In 'httpd.conf' please define these directives:

RewriteLog /tmp/rewrite.log
RewriteLogLevel 3

When getting error look into /tmp/rewrite.log, access_log  and error_log and post here all related messages.
0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18804791
its not giving me any errors, its just not working. rewrite.log is blank.

access_log:
70.127.251.232 - - [27/Mar/2007:20:56:23 -0400] "GET /error/404 HTTP/1.1" 404 -

error_log:

[Tue Mar 27 20:56:23 2007] [error] [client 70.127.251.232] File does not exist: C:/www/crackerblack.dyndns.org/public_html/error
[Tue Mar 27 20:56:23 2007] [error] [client 70.127.251.232] File does not exist: C:/www/crackerblack.dyndns.org/public_html/error
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 27

Expert Comment

by:Nopius
ID: 18805242
If rewrite log is created by Apache then rewrite module is included.
If no logs there - your C:/www/crackerblack.dyndns.org/public_html/.htaccess is not picked up by apache and rewrite engine didn't turned on. Why - I dont' know. May be there are some Windows speific issues.

You said you did rewrite rules in httpd.conf. In what section did it (global/directory/virtual host)?
0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18806681
i made an include file for convienence. i have the file included in httpd.conf, the file is included just fine though... i've done a few test to make sure the file is included...

the include file i made has just the rewrite commands i displayed for you.
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18812683
In what section of Apache it is included?
0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18813230
i already told you, httpd.conf
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18813310
In httpd.conf there are many sections I mean <Directory> <VirtualHost> or just global?
0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18821528
oh, global.
0
 
LVL 27

Accepted Solution

by:
Nopius earned 125 total points
ID: 18821576
Ok.
1) Open your httpd.conf again and find <Directoru /.../htdocs> section - your document root directory
2) Place these directives inside <Directory .../htdocs> section:
RewriteEngine On
RewriteBase /
RewriteRule ^error/([0-9]+)$ error-pages/$1.php

3) Leave RewriteLog and RewriteLogLevel in global section

That's my configuration:
...
RewriteLog /tmp/rewrite.log
RewriteLogLevel 5
<Directory "/u10/v/vA0/usr/htdocs">
RewriteEngine On
RewriteBase /
RewriteRule ^error/([0-9]+)$ error-pages/$1.php
...
4) Remove all .htaccess files from your htdocs directory

I just tested it and it works here.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordpress limitations 4 103
Problem to go to page 12 81
Missing Apache mod_DBD packages in Centos 7 2 65
Apache/PHP: Cannot make phpinfo() and phpmyadmin work 4 33
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now