Solved

Apache MOD_REWRITE trouble

Posted on 2007-03-27
14
177 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
Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

689 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