MattMeister
asked on
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
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
The AllowOverride is enabled?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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.
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.
ASKER
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
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
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
If yes, i think this is right setting:
RewriteEngine on
RewriteBase /mod_rewrite
RewriteRule ^test/([0-9]+)$ test.php?id=$1
RewriteBase /mod_rewrite/
ASKER
>>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
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
Sorry...
RewriteRule ^test/([0-9]+)$ test.php?id=$1 [R]
RewriteRule ^test/([0-9]+)$ test.php?id=$1 [R]
ASKER
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
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
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.
It looks like Apache is finding a command (php_value) that it doesn't like, and stopping processing of .htaccess files.
ASKER
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?!
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?!
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...
RewriteEngine on
RewriteRule ^/mod_rewrite/test/([0-9]+
I just tested it with this entries and it worked for me...
ASKER
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
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/.
ASKER
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
just need to get the htaccess mod rewrite working now
ASKER
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,FollowSym Links,Exec CGI,MultiV iews
and also for AllowOverride
Options,FileInfo,AuthConfi g,Limit
Thanks for your help!
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,FollowSym
and also for AllowOverride
Options,FileInfo,AuthConfi
Thanks for your help!
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.
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.
Apache: The Definitive Guide
http://skaiste.elekta.lt/Books/O'Reilly/Bookshelfs/books/linux/apache/index.htm
and the part about Options directive:
http://skaiste.elekta.lt/Books/O'Reilly/Bookshelfs/books/linux/apache/ch03_11.htm
http://skaiste.elekta.lt/Books/O'Reilly/Bookshelfs/books/linux/apache/index.htm
and the part about Options directive:
http://skaiste.elekta.lt/Books/O'Reilly/Bookshelfs/books/linux/apache/ch03_11.htm
Another (faster) link to the "Apache: The Definitive Guide"
http://www.hk8.org/old_web/linux/apache/index.htm
http://www.hk8.org/old_web/linux/apache/index.htm
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
http://docs.rinet.ru/Apachu/index.htm
and the part abuut Options:
http://docs.rinet.ru/Apachu/asg09.htm#E68E90
ASKER
Thanks for all your help :)
duh. it should read: thanks for all your help, mrielf.