Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Enabling Mod Rewriting

Posted on 2004-10-24
22
Medium Priority
?
791 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
Comment
Question by:MattMeister
[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
  • 10
  • 9
  • 2
  • +1
22 Comments
 
LVL 5

Expert Comment

by:mrielf
ID: 12393681
The AllowOverride is enabled?
0
 
LVL 5

Accepted Solution

by:
mrielf earned 2000 total points
ID: 12393691
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
ID: 12393713
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:MattMeister
ID: 12393977
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
ID: 12394841
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
ID: 12395215
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
ID: 12395226
RewriteBase /mod_rewrite/
0
 

Author Comment

by:MattMeister
ID: 12395263
>>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
ID: 12395340
Sorry...

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

Author Comment

by:MattMeister
ID: 12395409
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
ID: 12396305
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
ID: 12396359
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
ID: 12397799
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
ID: 12399535
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
ID: 12399609
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
ID: 12399733
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
ID: 12401804
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
ID: 12401939
0
 
LVL 5

Expert Comment

by:mrielf
ID: 12401966
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
ID: 12401989
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
ID: 12410548
Thanks for all your help :)
0
 
LVL 3

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month7 days, 18 hours left to enroll

610 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