Forum Moderators: phranque
I am unable to get mod-rewrite to run. Any ideas on set up, please?
The LoadModule rewrite_module modules/ApacheModuleRewrite.dll line of code seems to be present and the hash has been removed. However, if I run "apache -l" the module is not shown as present.
I seem to remember somewhere reading about needing to place an activate-module line somewhere.
Thankyou,
Thanks for your reply. I'll keep looking.
i myself run an apache 1.3.20 on my win2000 machine.
the line in my httpd.conf file to load the module looks like this:
LoadModule rewrite_module modules/mod_rewrite.so
are you sure your apache uses dllibraries?
I've looked at the forum thread suggested and seem to think that I've got all the required lines of code in place.
For example:
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
I've upgraded to Apache 1.2.23 and notice that the .dll files are no longer there.
Things still do not seem to be working.
Any other ideas will be welcome.
I have a .htaccess file called "my.htaccess" in a directory called "E:/apache/htdocs/re_write_test".
The line of code in the mt.htaccess is:
RewriteEngine on
RewriteRule ^news(.*)\.html$ shownews.php?id=$1.
The line of httpd.cof file identifying the my.htaccess file is:
AccessFileName my.htaccess
The error.log gives the following errors:
[Thu Mar 21 21:57:34 2002] [error] [client 127.0.0.1] File does not exist:
e:/apache/htdocs/re_write_test/news1.html
Also it gives this error on starting up the service:
[Thu Mar 21 22:08:35 2002] [error] [client 127.0.0.1] Premature end of script headers: e:/php4/php.exe.
Thank you for your help.
By the way, PHP is working despite the error message.
Thanks
Ok, no solutions - just suggestions.
Firstly, check that in httpd.conf that you allow overrides.
<Directory />
Options # as before
AllowOverride All
</Directory>
(if this is a live hosting server then not a good idea - but for a test server it's fine.)
Next test my.htaccess file is being used (possibly: invalid httpd.conf or that my.htaccess has a limited range of functions) - to test this put in
ErrorDocument 404 /error.html
And check that you get your error document displayed OK.
Alternatively try using .htaccess - with the same rules.
I hope this gets you closer to a working mod_rewrite.
Thank you for your reply. I really appreciate your help.
I've tried your suggestions with some success. The purpose-made 404 ("error.html")file does not show when the note1.html file is called (you will recall that "note1.html" is supossed to resolve in calling "shownews.php?id=1"), which I suppose shows that it is not being read. However, I cannot create a file with no prefix (i.e. a file named ".htaccess") using notepad. Is this possible in windows?
Sorry to be such a pest>
I've named the file "htaccess.txt" in Notepad and then tried to change it in Windows Explorer to ".htaccess". It keeps telling me that I can't due to the fact that "You must type a file name"(i.e. with a file prefix). Where am I going wrong?
Finally, I have changed the following "AllowOverride" expressions:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Alias /icons/ "E:/Apache/icons/"
<Directory "E:/Apache/icons">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# "E:/Apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "E:/Apache/cgi-bin">
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
Am I being thick? (Please be kind when answering that question.)
With thanks yet again.
In Windows Explorer click on:
Tools>>Folder Options...>>File Types>>New
It will ask for a file extension. Type in ".htaccess" then click "ok". You will be shown the details for ".htaccess". Click on "Change", select a program from a list (Notepad or some other text editor). Afterwords you should be able to save and edit .htaccess files with Notepad.
I've just found something interesting. The ReWrite code in the htaccess file is:
"ErrorDocument 404 E:/apache/htdocs/error.html
RewriteEngine on
#RewriteBase /
RewriteRule ^news(.*)\.html$ shownews.php?id=$1"
The intention is that news1.html will be parsed as "shownews.php?id=1".
If I enter "shownews.php?id=1" into the browser the return field is as expected. However, If I input "news1.html", I get an Explorer 404 page: If I enter "snews.html", I get my "error.html" page as identified in the htaccess code. So the file seems to be being read.
Is it the ReWrite code?
RewriteEngine on
RewriteRule ^/news(.*)\.html$ /shownews.php?id=$1
Assuming your two files are in the web root folder.
Should do it.... let me know ;)
The rewritebase option is very useful in situations where your running under a couple of sub dirs ... eg. /dir1/dir2/news3.html
Is written more easily as
RewriteEngine on
RewriteBase /dir1/dir2
RewriteRule ^/news(.*)\.html$ shownews.php?id=$1
HTH
Thank you once again for your patience.
I have altered my .htaccess file to your posted code as I found that you had placed an extra forward slash infront of the shownews.php statement.
Unfortunately, it still does not work. However, I continue to get the standard Microsoft 404 screen if I request "http://localhost/news1.html" and the error.log does not log an error. But if I request "http://localhost/news1.html" I get my purpose made "error.html" file and the error.log shows
"[Mon Mar 25 19:23:13 2002] [error] [client 127.0.0.1] File does not exist:e:/apache/htdocs/nejws1.html"
Something is happening but I cannot grasp what. Or where to start looking.
Lets go back a stage and try a very simple rewrite rule
RewriteEngine on
RewriteRule ^/test\.html$ /works.html
Create only the file works.html - remove the errordocument and then request test.html - With that test we know that re_write is either working or not.
Guys - feel free to step in with the answer anytime :)
I've tried your test without success, so I assume that mod_rewrite isn't working. I get a standard MS 404 file when test.html is requested.
The error log gives only:
[Tue Mar 26 07:16:03 2002] [error] Cannot remove module mod_php4.c: not found in module list
[Tue Mar 26 07:29:27 2002] [error] [client 127.0.0.1] File does not exist: e:/apache/htdocs/test.html.
Thank you for all your concern and help.
By the way, I like the Norfolk artists web site. I live in Cambridgeshire, only a stone's throw away from the North-West Norfolk coast.
RewriteRule ^news(.*)\.html$ /shownews.php?id=$1
Many thanks to all who have helped.