Solved

Enabling Mod Rewriting

Posted on 2004-10-24
769 Views
Last Modified: 2012-08-14
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
Question by:MattMeister
    22 Comments
     
    LVL 5

    Expert Comment

    by:mrielf
    The AllowOverride is enabled?
    0
     
    LVL 5

    Accepted Solution

    by:
    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
     
    LVL 5

    Expert Comment

    by:mrielf
    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
     

    Author Comment

    by:MattMeister
    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
     

    Author Comment

    by:MattMeister
    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
     
    LVL 5

    Expert Comment

    by:mrielf
    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
     
    LVL 5

    Expert Comment

    by:mrielf
    RewriteBase /mod_rewrite/
    0
     

    Author Comment

    by:MattMeister
    >>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
     
    LVL 5

    Expert Comment

    by:mrielf
    Sorry...

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

    Author Comment

    by:MattMeister
    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
     
    LVL 18

    Expert Comment

    by:arantius
    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
     

    Author Comment

    by:MattMeister
    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
     
    LVL 5

    Expert Comment

    by:mrielf
    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
     

    Author Comment

    by:MattMeister
    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
     

    Author Comment

    by:MattMeister
    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
     

    Author Comment

    by:MattMeister
    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
     
    LVL 3

    Expert Comment

    by:andYetAnotherLoginName
    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
     
    LVL 5

    Expert Comment

    by:mrielf
    0
     
    LVL 5

    Expert Comment

    by:mrielf
    Another (faster) link to the "Apache: The Definitive Guide"
    http://www.hk8.org/old_web/linux/apache/index.htm
    0
     
    LVL 5

    Expert Comment

    by:mrielf
    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
     

    Author Comment

    by:MattMeister
    Thanks for all your help :)
    0
     
    LVL 3

    Expert Comment

    by:andYetAnotherLoginName
    duh. it should read: thanks for all your help, mrielf.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    877 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

    14 Experts available now in Live!

    Get 1:1 Help Now