Forum Moderators: bakedjake
My web root is C:\mysite\
The htaccess file is sitting in C:\mysite\getimage\ht.access (yes '.' is in the wrong place, but win don't like files begining with '.''s and I've configued apache to use it.
In general. The site is working fine, the htaccess file it being read etc. But the code inside it isn't working.
I have tried the following:
RewriteEngine on
RewriteRule ^C:\\mysite\\getimage\\.$ C:\\mysite\\getimage\\getimage.php
RewriteEngine on
RewriteBase C:\\mysite\\getimage\\
RewriteRule ^.$ getimage.php
RewriteEngine on
RewriteBase /getimage
RewriteRule ^.$ getimage.php
And heaps of other variations. Sometime I get a syntax error etc. But most of the time, and for the above. When I make a request for [localhost...] I get this in the error log:
"[Tue Feb 12 19:54:23 2002] [error] [client 127.0.0.1] File does not exist: c:/mysite/getimage/RANDOM_NAME.jpg"
Please help me before I go insane.
Thanks,
Justin.
Place this in your .htaccess in your getimage dir (don't want to slow other requests down).
RewriteEngine on
RewriteBase /getimage/
RewriteRule ^(.*)$ getimage.php [T=application/x-httpd-cgi,L]
Best mod_rewrite cookbook - [engelschall.com...]
Lots of other options - once you get a simple example going you'll grok it.
This is .htaccess in your getimage directory.
RewriteEngine on
RewriteBase /getimage/
RewriteRule ^(.*)$ /imagetest.html [L]
By testing with this you know that the problem is with your script and not your apache set up. I assume that mod_rewrite is in your version of apache - it is on my NT apache.
If it works its your script.
If it doesn't - theres a problem with your apache install - ,aybe not including mod_rewrite, start checking logs and type the error messages that you see into Google.
Good luck
It seems to be missing the /getimage/ folder. tried it both /getimage/ and /
RewriteBase /getimage/
RewriteRule /getimage/^(.*)$ /getimage/test.html [L]
This works if I request test.html. But just returns a file not found if I type in garbage.
mod_rewrite seems to be on else I wouldn't have gotten bad agrument errors ealier on. And it's not commented out or anything in the httpd.conf file.
The reason why this:
RewriteBase /getimage/
RewriteRule /getimage/^(.*)$ /getimage/test.html [L]
Would not work because you were using Getimage twice.
Mod_Rewrite is looking to convert anything in /getimage/getimage/* to /getimage/getimage/test.html
Because you are now only using getimage in your rewritebase and not in the rules it is now working because it converts /getimage/* to /getimage/test.html
Well hopefully thats why, if not someone please correct me :)
RewriteEngine on
RewriteBase /some-dir/
RewriteRule ^(.*) /junk.php [L]
This, however, ends up rewriting so that the actual file opened is not
G:/htdocs/some-dir/junk.php
as I want, but is one level up, that is
G:/htdocs/junk.php
Everything I change to get this to go down to /some-dir breaks the script and I get a 404
Welcome to the boards,
RewriteEngine on
RewriteBase /some-dir/
RewriteRule ^(.*) /junk.php [L]
Basically your / in front of the junk.php says get it from the root directory of your webserver.
Try:
RewriteEngine on
RewriteBase /some-dir/
RewriteRule ^(.*) /some-dir/junk.php [L]
or more generically
RewriteEngine on
RewriteBase /some-dir/
RewriteRule ^(.*) junk.php [L] # notice lack of slash.
Gethan
>your / in front of the junk.php says get it from the root directory
That's what I figured, however, that's the only way I can get it to work. I've tried all sorts of combinations - absolute paths, with and without RewriteBase, etc etc.
>RewriteBase /some-dir/
>RewriteRule ^(.*) /some-dir/junk.php [L]
This just hangs up so I can't even get the error message for it, but RewriteBase should already be appending the /some-dir/ so the result should be
/some-dir/some-dir/junk.php
I think that's why this chokes.
>RewriteBase /some-dir/
>RewriteRule ^(.*) junk.php [L] # notice lack of slash.
This gives me a 400 error and doesn't seem to rewrite at all. There is no error log message for it, but it gives me
127.0.0.1 - - [26/Apr/2002:10:00:49 -0700] "GET /ergophobia/climb2 HTTP/1.1" 400 293
where it want
[localhost...]
to map to
[localhost...]
I also tried
RewriteBase /
RewriteRule ^/some-dir/(.*) /some-dir/junk.php [L]
RewriteBase /some-dir/
RewriteRule ^(.*) ./junk.php [L]
# RewriteBase omitted
RewriteRule ^/some-dir/(.*) /somedir/junk.php [L]
It always just hangs up.
>Welcome to the boards
Thanks. Great set of forums. I got here by Google and since I don't feel comfortable asking a question on a forum I don't take part in, I cruised around. Learned a bit and, hopefully offered some useful advice in a couple of posts. I'll keep coming back and hopefully with more answers than questions!
Hopefully a mod will spot this and move it across sometime :)
Ok now for some specifics, the rules I posted work fine on my system setup (Linux, Apache 1.3.22, with mod_rewrite and php 4.1). The RewriteBase only applies to the request and not the redirection. (I'll double check the docs for this sometime - but have never seen it work otherwise).
But something wierd is going on with your system - obviously without access to it the only help I can give is theoretical - but this is a little script that I find very useful for diagnosing redirect problems.
[perl]
<html>
<head>
<title>Variables</title>
</head>
<body>
<h1>TEST SCRIPT</h1>
<?php
print "<p><b>Post Vars</b><br>";
$array = $HTTP_POST_VARS;
foreach ($array as $key => $value) {
print "$key: $value<br>\n";
}
print "<p><b>Get Vars</b><br>";
$array = $HTTP_GET_VARS;
foreach ($array as $key => $value) {
print "$key: $value<br>\n";
}
print "<p><b>Server Vars</b><br>";
$array = $HTTP_SERVER_VARS;
foreach ($array as $key => $value) {
print "$key: $value<br>\n";
}
print "<p><b>Env Vars</b><br>";
$array = $HTTP_ENV_VARS;
foreach ($array as $key => $value) {
print "$key: $value<br>\n";
}
print "<p><b>Cookie Vars</b><br>";
$array = $HTTP_COOKIE_VARS;
foreach ($array as $key => $value) {
print "$key: $value<br>\n";
}
?>
</body>
</html>
[/perl]
Make your redirect rules redirect to this script.
Take particular care and attention of the server vars in this case, particularly: anything starting with REDIRECT, REQUEST_URI, SCRIPT_FILENAME and SCRIPT_NAME.
I hope this lets you get to the bottom of this problem -- good luck
Gethan
Thanks, but something is just weird beyond what I can figure out and running a script to show the variables doesn't really help because everything looks normal when it works, and, when it doesn't work, it gives a server error, page not found, infinite loop in Apache, something like thanks.
I think I'll just put up with redirect to server root on my Windows version, since that's actually how I want it to run on the Linux version anyway.
Cheers,
Tom