Jump to content

Recommended Posts

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? :'(

Link to comment
https://forums.phpfreaks.com/topic/252325-strange-redirect-behavior/
Share on other sites

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.

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.

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.

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.

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 :(

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. 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.