Solved

Apache MOD_REWRITE trouble

Posted on 2007-03-27
14
172 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
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

12 Experts available now in Live!

Get 1:1 Help Now