Dudditz Posted March 24, 2008 Share Posted March 24, 2008 I recently moved a small script from a server with php5.2.4 to one with php5.2.5 and certain areas have stopped working. After some debugging I went back to square one and set up 2 files as follows: .htaccess RewriteEngine On RewriteRule ^(.+)/(.+)/(.+).png /image.php?type=$1&style=$2&tag=$3 image.php <?php echo $_GET['type']; ?> For some reason, the type will add a file extension if there is a file name existing in the directory threrfore returning the wrong data to my script. If there is no file by the type it will display properly. example: if $_GET['type'] is image in the url mydomain.wer/image/some/picture.png the $_GET will return image.php instead of image since there exists an image.php file in directory. Its like the server is searching the directory for a file by that name instead of just returning the url part like its supposed to. Does anyone know why this is happening? thanks Quote Link to comment Share on other sites More sharing options...
alexL Posted March 24, 2008 Share Posted March 24, 2008 I am not that a big regexp expert. Try first to see the phpinfo() difference on these 2 webservers (previous and new one). Also try RewriteRule ^(.+)/(.+)/(.+)\.png /image.php?type=$1&style=$2&tag=$3 instead of RewriteRule ^(.+)/(.+)/(.+).png /image.php?type=$1&style=$2&tag=$3 Quote Link to comment Share on other sites More sharing options...
Dudditz Posted March 24, 2008 Author Share Posted March 24, 2008 I am not that a big regexp expert. Try first to see the phpinfo() difference on these 2 webservers (previous and new one). Also try RewriteRule ^(.+)/(.+)/(.+)\.png /image.php?type=$1&style=$2&tag=$3 instead of RewriteRule ^(.+)/(.+)/(.+).png /image.php?type=$1&style=$2&tag=$3 I'll look into the php differences but the RewriteRule change did not solve the issue. For now, I have simply renamed the image.php to image1.php and it works When I echo $_GET['type']; with any name in that url location that has the same name of a file within the directory, it will echo the filename instead of the $_GET from url. If I put example in the url, it will echo example until I create an example.ext in which it will then echo example.ext Driving me nuts but I will rename filenames for temporary measure. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 You might want to apply a rewrite condition: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/(.+)/(.+)\.png /image.php?type=$1&style=$2&tag=$3 Also it may because you're using (.+) which I believe is greedy. What you should do is use character ranges: Full code RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z]+)/([a-z]+)/([a-z]+)\.png$ /image.php?type=$1&style=$2&tag=$3 [NC] Quote Link to comment 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.