Solved

Apache MOD_REWRITE trouble

Posted on 2007-03-27
14
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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