kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi I had an htaccess issue which I hope someone can help me with:- Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} ^.*\.gif$ RewriteRule ([a-zA-Z]+)\.gif$ GrabImage.php?username=$1 The idea is that any request to a gif in that directory should be passed to GrabImage.php. However while if I invoke GrabImage.php directly it works fine, if I specify an image name instead I get a 404 error. If I change "GrabImage.php" to "/Index.php" in the script it redirects it successfully to the root index script (happens to be a phpbb forum) for that domain. If I specify a gif in that directory with a name which is not just alphabetics (so the RewriteRule is not met) then the image is served perfectly. If I rename the image and try again with the new name (which the RewriteRule meets) then I get a 404 error. I suspect I have missed something simple here, and it does work fine on my wamp setup on my desktop machine, just not when I upload it. Thanks in advance. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159730-htaccess-issue/ Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 In that case, try - Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} ^.*\.gif$ RewriteRule ([a-zA-Z]+)\.gif$ GrabImage.php?username=$1 Quote Link to comment https://forums.phpfreaks.com/topic/159730-htaccess-issue/#findComment-842549 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Author Share Posted May 26, 2009 Hi Cheers, but no difference. What is "Rewritebase /" attempting to do? Is is trying to specify that any requests are not redirected by appache to another directory? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159730-htaccess-issue/#findComment-842574 Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteBase Well I assumed GrabImage.php is in your root directory. You sure you have the path right? Quote Link to comment https://forums.phpfreaks.com/topic/159730-htaccess-issue/#findComment-842895 Share on other sites More sharing options...
kickstart Posted May 29, 2009 Author Share Posted May 29, 2009 Hi No, GrabImage is in the directory with the images. If I put a slash in front of GrabImage.php (or some other script name I put there such as Index.php) it will pick it up from the root. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159730-htaccess-issue/#findComment-845064 Share on other sites More sharing options...
Ken2k7 Posted May 29, 2009 Share Posted May 29, 2009 So like: Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} ^.*\.gif$ RewriteRule ([a-zA-Z]+)\.gif$ GrabImage/GrabImage.php?username=$1 Did I understand you correctly? Quote Link to comment https://forums.phpfreaks.com/topic/159730-htaccess-issue/#findComment-845106 Share on other sites More sharing options...
kickstart Posted June 2, 2009 Author Share Posted June 2, 2009 Hi Had more of a play. The directory is like:- /publichtml/sitedirectory/subdirectory1/subdirectory2/ subdirectory2 contains the GrabImage.php script and the .htaccess file. Also an Index.php that is a clone of GrabImage.php. If I try the following it doesn't work. Just get a 404 error Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} ^.*\.gif$ RewriteRule ([a-zA-Z]+)\.gif$ Index.php?username=$1 If I try the following it pics up the Index.php from that sites directory (ie /publichtml/sitedirectory/Index.php) Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} ^.*\.gif$ RewriteRule ([a-zA-Z]+)\.gif$ /Index.php?username=$1 If I try the following it does actually work. Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} ^.*\.gif$ RewriteRule ([a-zA-Z]+)\.gif$ /subdirectory1/subdirectory2/Index.php?username=$1 "RewriteBase /" appears to have no effect. My understanding was that the rewrite rule was relative to the local directory unless specified otherwise but that doesn't appear to be the case. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159730-htaccess-issue/#findComment-847705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.