imperium2335 Posted December 2, 2011 Share Posted December 2, 2011 Hi, this is driving me insane. I have the following in my .htaccess file: Options +FollowSymlinks RewriteEngine On RewriteRule ^wedding-cakes/(.*)\.html /cakes.php?target=$1 RewriteRule ^chocolate-cups-towers/(.*)\.html /cakes.php?target=$1 RewriteRule ^corporate-cakes/(.*)\.html /cakes.php?target=$1 RewriteRule ^adult-birthday-cakes/(.*)\.html /cakes.php?target=$1 RewriteRule ^childrens-birthday-cakes/(.*)\.html /cakes.php?target=$1 RewriteRule ^saucy-cakes/(.*)\.html /cakes.php?target=$1 RewriteRule ^christmas-cakes/(.*)\.html /cakes.php?target=$1 RewriteRule ^christening-cakes/(.*)\.html /cakes.php?target=$1 The problem is that all of these except for "RewriteRule ^chocolate-cups-towers/(.*)\.html /cakes.php?target=$1" dont work. The pages definitely exists and you can see them at http://www.sweetart.co.uk/cake-gallery.php. Any ideas on why it doesn't work for the others? :'( Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/ Share on other sites More sharing options...
premiso Posted December 2, 2011 Share Posted December 2, 2011 That seems a mess, you can do it with 1 rewrite statement: RewriteRule ^.*-cakes/(.*)\.html /cakes.php?target=$1 [L] Try that out and see how it works for ya. As to why only 1 was working, well the [L] says "Stop at this rule if it is true". Leaving it out, the rewrites check everything else, and that would more than likely by why it was flaking out. Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293527 Share on other sites More sharing options...
imperium2335 Posted December 2, 2011 Author Share Posted December 2, 2011 Hi, Thanks but didn't work, I tried replacing '.*' with [a-z0-9]* and its a success. Strange because I have never had problems with using (.*) before. Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293528 Share on other sites More sharing options...
premiso Posted December 2, 2011 Share Posted December 2, 2011 Thanks but didn't work, I tried replacing '.*' with [a-z0-9]* and its a success. Well glad you got it working, and yea, you can try using (.*), but if you do that you would need to change target=$1 to target=$2 but if the [a-z0-9]* will capture everything you may have there, that will work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293529 Share on other sites More sharing options...
imperium2335 Posted December 2, 2011 Author Share Posted December 2, 2011 Thanks, it's doing my head in, now it isn't working, it seems like it worked for a few minutes but now none of the redirects work Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293531 Share on other sites More sharing options...
premiso Posted December 2, 2011 Share Posted December 2, 2011 Thanks, it's doing my head in, now it isn't working, it seems like it worked for a few minutes but now none of the redirects work Did you remove all of the redirects except the one I posted (with your modification of course)? Also, sometimes browsers, like Chrome, like to cache certain items. I would suggest using Firefox to test (if you were using Chrome) to prevent a false positive. Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293533 Share on other sites More sharing options...
imperium2335 Posted December 2, 2011 Author Share Posted December 2, 2011 I'm using firefox. The reason I use all those different ones is because they are real gallery pages. Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293536 Share on other sites More sharing options...
premiso Posted December 2, 2011 Share Posted December 2, 2011 The reason I use all those different ones is because they are real gallery pages. I can understand that, but you really do not need to use multiple ones. If security is your deal, set an allowed array in the cakes.php file or similar and 404 anything that is not in that list. But having multiple re-writes causes problems. Try removing them all, and replacing them with the one I posted and see how it runs. If nothing else, add the [L] after all of them, so the processing stops when it hits a matching rule. Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293538 Share on other sites More sharing options...
imperium2335 Posted December 2, 2011 Author Share Posted December 2, 2011 Thanks for your help, I have tried what you suggested and I get exactly the same results. :'( If I have only : RewriteRule chocolate-cups-towers/([a-z0-9]*)\.html /cakes.php?target=$1 RewriteRule wedding-cakes/([a-z0-9]*)\.html /cakes.php?target=$1 It works, but when I add in ANY of the others, it breaks them all Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293543 Share on other sites More sharing options...
imperium2335 Posted December 2, 2011 Author Share Posted December 2, 2011 Ok, it seems that it is totally random, now it doesn't work with just 2 of them, but did a moment ago. could my web hosts server be crap? Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293544 Share on other sites More sharing options...
premiso Posted December 2, 2011 Share Posted December 2, 2011 RewriteRule ^.*-cakes/(.*)\.html /cakes.php?target=$1 [L] Try that first, see how it goes. If that does not work, and you still insist on keeping multiple rewrites: RewriteRule chocolate-cups-towers/(.*)\.html /cakes.php?target=$1 [L] And the .* should work, in both spots. It is valid, so yea, if that is messing up then something else is messing up. You may also check your APACHE logs (access and error) as they may contain a clue. But the [L] is key, do not take that out either way. Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293546 Share on other sites More sharing options...
imperium2335 Posted December 2, 2011 Author Share Posted December 2, 2011 Have done exactly what you have wrote, but I am back to square one now with just the: RewriteRule chocolate-cups-towers/(.*)\.html /cakes.php?target=$1 [L] working Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293549 Share on other sites More sharing options...
imperium2335 Posted December 2, 2011 Author Share Posted December 2, 2011 I think I know why it is happening! I have noticed that my gallery pages all have the same name as my abstract redirect folders, i.e: The Christmas cake gallery is called 'christmas-cakes.php', and its redirect to any picture in the gallery is for example, 'christmas-cakes/chocolate-strawberries-christmas-cake.html'. That would explain why my chocolate cup pictures are working but nothing else, because the cup gallery is called 'chocolate-cup-towers.php' and its redirects for pictures in there are 'chocolate-cups-towers/decorative-chocolate-cups.html'. Note the 's' in the redirect. So, it must be getting confused for some reason, how ever I have no idea how to fix this other than changing the file names etc which is a massive job. Any one have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/#findComment-1293624 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.