I really appreciate the help that I got for my previous question - I think it was just the answer I was looking for! I'm working on another .htaccess file for a different client and I'm back with some (probably) basic questions.
Here's the setup: The client is a group of restaurants. Originally, they had several websites for each of their restaurant, and a separate website where people could order food from any of those restaurants to be shipped to them. Now, the client would like to get rid of the separate food ordering website and redirect the various pages of it to the websites for the different stores.
I came up with a rough draft which I sent to my supervisor, and she came back with this version:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^a-store$ [NC]
# Redirect [restaurant1] related pages to example.com pages
RewriteRule ^.*ED-03.*$ http://www.example.com/gift-shop/ [R=301]
RewriteRule ^.*c-Ed_DebevicAns.*$ http://www.example.com/gift-shop/ [R=301]
RewriteRule ^.*eds_p3.*$ http://www.example.com/menus/ [R=301]
RewriteRule ^.*eds_p5.*$ http://www.example.com/promotions/gift-certificates/ [R=301]
RewriteRule ^.*eds_p7.*$ http://www.example.com/cateringevents/ [R=301]
RewriteRule ^.*eds_p8.*$ http://www.example.com/promotions/ [R=301]
# Redirect [restaurant2] related pages to example2.com pages
RewriteRule ^.*edw_p2.*$ http://example.net/locations/ [R=301]
RewriteRule ^.*edw_p5.*$ http://example.net/product-category/gift-certificate/ [R=301]
RewriteRule ^.*c-EdwardoAns.*$ http://example.net/shop/ [R=301]
RewriteRule ^.*EDW-01.* http://example.net/shop/edwardos-9-stuffed-spinach-pizza/ [R=301]
RewriteRule ^.*EDW-02.* http://example.net/shop/edwardos-9-stuffed-sausage-pizza/ [R=301]
RewriteRule ^.*EDW-08.* http://example.net/shop/edwardos-9-stuffed-cheese-pizza/ [R=301]
# Redirect [restaurant3] related pages to example.org pages
RewriteRule ^.*c-GinoAns_East.*$ http://www.example.org/product-category/deep-dish/ [R=301]
RewriteRule ^.*gino_p5.*$ http://www.example.org/product-category/gift-certificate/ [R=301]
RewriteRule ^.*GINO-01.*$ http://www.example.org/shop/deep-dish-cheese-pizza-11/ [R=301]
RewriteRule ^.*GINO-02.*$ http://www.example.org/shop/deep-dish-crumbled-sausage-pizza-11/ [R=301]
RewriteRule ^.*GINO-04.*$ http://www.example.org/product-category/deep-dish/ [R=301]
# Redirect all [restaurant4] pages to example4.com
RewriteRule ^.*[m|M]it.*$ ht
tp://example4.com [R=301,L]
So, I have a few questions about this. 1) it's my understanding that a RewriteCond only applies to the RewriteRule
directly below it, that it can't apply to more than one RewriteRule, and if you want all your rules to have conditions, you have to put a RewriteCond above every RewriteRule. My supervisor says that this is not the case as long as only the very last RewriteRule has an L flag. Is this true?
Which brings me to my next question: I thought that you were supposed to put an L flag after every rule. That good .htaccess practice is, you work from most specific to least specific, and put an L flag after every rule, so that if the server finds a rule that applies to the requested URL, it applies the first (most specific) rule that it finds, and it doesn't look for any other rules once it triggers the first one. That way it avoids confusion and possible redirect loops.
Also, in her email with the corrections, she sent me this statement: "A most important thing is to test with 302, not 301. While the .htaccess I sent you has 301, the test site is using 302 so your browser won’t trick you into thinking something works when it doesn’t, or trick you into thinking something doesn’t work when it does." What does this mean? How would testing something with 301s make your browser trick you into thinking something works when it doesn't, or not working when it does? Since I'm not 100% certain about the difference other than that one is permanent and one is temporary, I have no idea why this statement might be the case.
[edited by: Ocean10000 at 8:19 pm (utc) on Jan 14, 2015]
[edit reason] Unlinked URLs [/edit]