Forum Moderators: phranque
Except I can't get Mod Rewrite to work on any of my test machines.
Windows XP SP1, Apache 1.3.x and PHP 4.x
Apache's httpd.conf has the following line uncommented
LoadModule rewrite_module modules/mod_rewrite.so
I set up a file as such...
c:\htdocs\.htaccess with the following content
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^foo.htm foo.php
c:\htdocs has a file called foo.php, the .htaccess file and nothing else.
My expectation is that I can enter [localhost...] into my browser, and have it display content the same as [localhost...]
Instead I get a 404 error.
I have been through several Mod Rewrite tutorial sites, which indicate I'm doing everything right. Does anyone know what might be causing the problem? Any help greatly appreciated.
Next, if you have write access to httpd.conf, that's really the preferred place for RewriteRule lines; the performance will be MUCH better. That's not always an option, but you should be aware.
As a matter of syntax, the RewriteRule should have a '[L]' at the end:
RewriteRule ^foo.htm$ foo.php [L]
mod_rewrite requires that the 'FileInfo' option be active for the AllowOverride line which pertains to the directory containing the .htaccess file; in this case, you should have a line something like:
<Directory C:\htdocs>
AllowOverride none
If all of the above are true, your next step is likely to enable mod_rewrite's logging (in your httpd.conf) like so:
RewriteLog /path/to/rewrite.log
RewriteLogLevel 9
Good luck. =)
Yes, the other AddModule line is uncommented in Apache 1.3
When I change AllowOverride none to AllowOverride All or AllowOverride FileInfo, I get a 500 error instead of a 404.
The .htaccess file I have works fine on my webhost (Apache/Linux), but it's not working on my local windows test server. I'm aware the file isn't "best practice", I deliberately kept it simple to start with just to get it working. (but thanks for the tips - very useful to know)
Here is a snippet from httpd.conf - it's default apart from AllowOverride.
<Directory "C:/htdocs">
#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks MultiViews
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride FileInfo
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
When I change AllowOverride none to AllowOverride All or AllowOverride FileInfo, I get a 500 error instead of a 404.
So, two things. 'All' sets 'Options', so the caveat I posted above regarding that applies. Second, if you're getting a '500' error, it likely means the .htaccess file is configured incorrectly; syntax errors or the use of directives in .htaccess which aren't available to it can cause that error. Apache should log the precise reason in its ErrorLog.