• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 793
  • Last Modified:

Enabling Mod Rewriting

My set up:

Win XP
Apache 1.3

I am having trouble getting mod rewriting working, i added a rewrite rule to a htaccess file and got a 500 internal server error, so i checked the error log and it said:

Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration

So i opened up my httpd.conf file and uncommented

LoadModule rewrite_module modules/mod_rewrite.so AND
AddModule mod_rewrite.c

Restarted Apache but still got the 500 error so i checked the error log again and now it says:

RewriteEngine not allowed here

What else do i need to do?

Thank you

Edit: if relevant my htaccess file looks like this:

RewriteEngine on
RewriteBase /mod_rewrite
RewriteRule /test/([0-9]+) /test.php?id=$1
0
MattMeister
Asked:
MattMeister
  • 10
  • 9
  • 2
  • +1
1 Solution
 
mrielfCommented:
The AllowOverride is enabled?
0
 
mrielfCommented:
Here's a list of directives and settings you'll need to enable mod_rewrite:


* LoadModule rewrite_module <your_modules_path>/mod_rewrite.so

* AddModule mod_rewrite.c

* AllowOverride FileInfo Options -or-
* AllowOverride All

* Options +FollowSymLinks -or-
* Options +SymLinksIfOwnerMatch -or-
* Options All
0
 
mrielfCommented:
One more important thing!

One problem that crops up often is that of LoadModule order, particularly it seems on home-brew PHP installations. It's important to realize that Apache modules are executed in reverse order from that specified in the list of LoadModule directives. If you load PHP after loading mod_rewrite and set up the server to parse certain file types for PHP, then mod_rewrite won't be executed for any of those files that exist; PHP will be invoked first and it will bypass mod_rewrite. The php module should be loaded before mod_rewrite.so to avoid this problem.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
MattMeisterAuthor Commented:
Hi mrielf,

Currently i have done the first two things you mentioned. I have not changed anything related to the override or options, im not sure where to add/modify these settings. I found these lines in my httpd.conf file which are labelled as the default settings...

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

But then later down i have:

<Directory "C:/Program Files/Apache Group/Apache/htdocs">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride Limit
    Order allow,deny
    Allow from all
</Directory>

(I have cut out the comments they included in the later) Which i presume overwrites the base settings.

Just to ensure i get it right can you show me exactly how it should look for mod rewrite to work. Also is there any security risks (or related issues) with setting either of these things to "All" ?

With regards to the PHP issue, I have the configuration lines later on in the file in the Aliases section, between:

<IfModule mod_alias.c>
and
</IfModule>

As this is after the modules are loaded in the conf file, if they are loaded in reverse order is this correct?

My knowledge of configuring Apache is quite limited so apologies if i am asking obvious questions.
0
 
MattMeisterAuthor Commented:
Ok i am getting there, i set AllowOverride to All and now mod rewrite is working however

It is rewriting the url and sending me to test.php but the query string is empty?!

See the first post in this thread for the code in my htaccess file
0
 
mrielfCommented:
you want to change http://yoursite/mod_rewrite/test/something to http://yoursite/mod_rewrite/test.php?id=something ?

If yes, i think this is right setting:

RewriteEngine on
RewriteBase /mod_rewrite
RewriteRule ^test/([0-9]+)$ test.php?id=$1

0
 
mrielfCommented:
RewriteBase /mod_rewrite/
0
 
MattMeisterAuthor Commented:
>>you want to change http://yoursite/mod_rewrite/test/something to http://yoursite/mod_rewrite/test.php?id=something ?

Yes, thats correct. I now have:

RewriteEngine on
RewriteBase /mod_rewrite/
RewriteRule ^test/([0-9]+)$ test.php?id=$1

But its still not working

It loads test.php but with no query string value

<?php
print_r($_GET);
?>

To show the contents of the GET array is empty
0
 
mrielfCommented:
Sorry...

RewriteRule ^test/([0-9]+)$ test.php?id=$1 [R]
0
 
MattMeisterAuthor Commented:
still not working...

I have just checked my error log again and now when i access the folder mod_rewrite it generates this error refering to the .htaccess

Invalid command 'php_value', perhaps mis-spelled or defined by a module not included in the server configuration

Do you have any idea whats causing this, i am not flaging any PHP values in my htaccess file, all thats in there is the 3 lines for the mod rewrite
0
 
arantiusCommented:
Check for .htaccess files in parent directories of mod_rewrite.

It looks like Apache is finding a command (php_value) that it doesn't like, and stopping processing of .htaccess files.
0
 
MattMeisterAuthor Commented:
There are no other htaccess files in the parent folders of this folder... and the only other ones i use work perfectly fine and for that matter don't have any php settings in them, i have no need as its just a test server, i can directly edit the php.ini

This is really bugging me i don't have a clue what the problem is

The only mention of php in this htaccess file is the .php extension, that surely can't be affecting it?!
0
 
mrielfCommented:
try to place the rewrite entries in httpd.conf not in .htaccess file.

RewriteEngine on
RewriteRule ^/mod_rewrite/test/([0-9]+)$ /mod_rewrite/test.php?id=$1

I just tested it with this entries and it worked for me...

0
 
MattMeisterAuthor Commented:
ok well it now works with it in the httpd.conf file however

1) i need to have it working with the htaccess files

and

2) its still generating that error even though i have removed the htaccess file from the folder
[Mon Oct 25 13:39:29 2004] [alert] [client 127.0.0.1] c:/program files/apache group/apache/htdocs/test/.htaccess: Invalid command 'php_value', perhaps mis-spelled or defined by a module not included in the server configuration
0
 
MattMeisterAuthor Commented:
oh fixed that error, didnt realise i had one in that directory... and also didnt realise a htaccess in a sub directory that wasnt being accessed would generate an error.

just need to get the htaccess mod rewrite working now
0
 
MattMeisterAuthor Commented:
haha! finally got it to work :D

I had options set to

Options All MultiViews

because it said something about having to explicitly declare multiviews... dont even know what it does though so removed it and it works now.

One last thing, could you explain to me... or point me to a page which explains what these things mean because i have no idea and would like to know.

Indexes,Includes,FollowSymLinks,ExecCGI,MultiViews

and also for AllowOverride

Options,FileInfo,AuthConfig,Limit

Thanks for your help!
0
 
andYetAnotherLoginNameCommented:
RewriteRule ^/mod_rewrite/test/([0-9]+)$ /mod_rewrite/test.php?id=$1

try uppercase URL in browser (like .../mod_rewrite/TEST/...) and it will fail. On Windows (and you DO use Windows, don't you ?), you have to add [NC] to the rule.
0
 
mrielfCommented:
Another (faster) link to the "Apache: The Definitive Guide"
http://www.hk8.org/old_web/linux/apache/index.htm
0
 
mrielfCommented:
Or you can use Apahe server survival Guide
http://docs.rinet.ru/Apachu/index.htm

and the part abuut Options:

http://docs.rinet.ru/Apachu/asg09.htm#E68E90
0
 
MattMeisterAuthor Commented:
Thanks for all your help :)
0
 
andYetAnotherLoginNameCommented:
duh. it should read: thanks for all your help, mrielf.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 10
  • 9
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now