htaccess 301 rewrite help

Hi All -



Just found a weird who-ha with the way the htaccess rewrite rules are working, and hoping someone may be able to shed some light for me.



I CAN get around - but htaccess has always been a weakness for me. Well, that and chocolate cake.



Situation -


  • Migrating from an old virtuemart commerce setup (Which was horrible BTW)
  • Have about 15-20 old categories to redirect to the new.



    OLD urls look like: “Domain.com

    NEW urls look like: “http://www.domain.com/childrens/



    The OLD urls return a status of 200 to the browser (Which is bad) versus keying the 404.



    Using a 301 in the htaccess:



    Redirect 301 /index.php?option=com_virtuemart&Itemid=53 [url]http://www.domain.com/childrens/[/url]



    literally - does nothing.



    Would any of the kind folks in here have any suggestions? Like I said… I am a hero when it comes to others areas, but htaccess and rewrite just spins my head!



    Thanks in advance,

You cannot redirect dynamic URL’s that way. You’ve got to use a more complex method to match your old url and redirect.



I had the same problem and never came up with a solution. This post I created may help though: [url]Redirect rule in .htaccess is taking me to the wrong place - Stack Overflow



You might also try contacting CS Cart support as I think the problem may come down to something particular in the default CS Cart .htaccess



Good luck!

Exactly why is “200” bad?



(Or are you just wanting to redirect the old URLs to the new addresses instead of internally remapping those addresses without any regard to search engine rankings? If so then you’re fine, go ahead and use whatever code you want) :cool:


[QUOTE]Redirect 301 /index.php?option=com_virtuemart&Itemid=53 [url]http://www.domain.com/childrens[/url][/QUOTE]



Your command actually isn’t all that bad but you might want to look more to “AliasMatch” instead of “Redirect”!





.

[quote name=‘jonahcoyote’]You cannot redirect dynamic URL’s that way. You’ve got to use a more complex method to match your old url and redirect.

[/quote]



Thanks Jonah - I figured I was going to need to use a “RewriteRule” bit of code in the htaccess. Just checking to see if anyone else had already done it with a VM to CS swap.


[quote name=‘jonahcoyote’]Exactly why is “200” bad?[/quote]



The old pages, which do not exist, do not trigger a 404 at all and send a status of 200 to the header auth, which is something Google frowns upon.



I had several other sites using a different app in the past that returned a 200 status, and not only is it bad for users who came expecting to find ABC info, but landed on the soft home page instead.



As far as the old > new urls - we have a LOT of existing inbound links out there after 8+ years of having an ecom site, I want to spread that link juice to the new locations, versus having it drop off the map. :slight_smile:



Thanks again for the replies.

I’m actually trying to make a subtle point here — though apparently too subtle! :smiley:



What I am saying is that you should keep your original URLs but SILENTLY remap or alias them all to your new correct updated URLs INSTEAD of using redirects (which is entirely different) so that visitors and search engines get the correct page irregardless of whether they use the old original URL or the new current one (and that goes for dynamic URLs too).



With the absence of a “redirect” as you would probably think of the word, the search engines will be fully unaware of any URL changes and you rankings on your original URLs will remain the same.



Regarding the earlier status “200” comment, you actually should leave status “200” fully in place but instead of showing the home page or some default error page, actually go ahead and deliver the correct requested page the visitor wanted by means of the old original URL.



[COLOR=“SlateGray”](For those who don’t fully understand what I just said, redirects can be setup SERVER side totally transparent and invisible to the visitor because everything is remapped entirely within the server delivering the content itself and no real “redirect” actually occurs. Alternatively, redirects can be setup on the CLIENT side and work by the server sending a signal to the visitor’s browser basically telling the browser to go to another web page [which is what those status codes are all about]. Most people are largely more familiar with the CLIENT side redirects which is sad because the SERVER side redirects actually help page rankings while the CLIENT side redirects can negatively impact your rankings and do in many cases)[/COLOR]



Quite simple to set this up actually and I’d be glad to give you a hand with that!



PS: No, you don’t necessarily need “Mod_ReWrite” rules either.

Spiral-



Since it is “Quite simple to set this up actually”, how about providing some instructions?



Or does the “be glad to give you a hand with that!” mean you are here just to drum up business?



Bob

If I were trying to “drum up business”, I’d leave a business card :slight_smile:



(What ever happened to “say what you mean and mean what you say?” LOL)



I’m fairly broadly recognized primarily for my expertise in server and network security with a background going back more than 33+ years in systems administration and other related areas and I was recently contacted at the request of more than a few web hosts and other forum users and asked to come here to “help users here” so that is precisely what I’m doing!



(I suppose that says something in itself :wink: )



On the flipside of that coin, my time is quite valuable, more than you’d probably imagine, and for some things such as this, it would be a whole lot easier and quicker for me to just do it than to type out a long and time consuming dissertation trying to explain it all



(though I’ve been known to do that too – writing long book essays)



PS: And “jobosales”, when I say “I will give you a hand” I mean that literally — no strings attached.

Great job guys, so instead of arguing over who said what and who can do what, why doesn’t somebody step up and offer some actual help? If you want money for it fine, say so, but if not and if its a simple solution and you feel generous enough to share, please do. End of story.



I personally spent well over a day trying to figure this out for a site, much of which is contained in this post ([url]http://stackoverflow.com/questions/2...access-problem[/url]) and never came up with a solution. The full .htaccess is posted there with a few different potential solutions. I was able to do static redirects for many of the links but I also left many of the links going no where. Oh well, Google will find us again eventually :slight_smile:


  • Jonah

@ Spiral -



Thanks for clarifying - Just trying to understand the benefit of doing it that way versus setting a simple rewriterule to handle it permanently. In effect, it sounds like I will ultimately have 2 pages with the same content under 2 separate URI’s, no?



I have been around the web for quite a while myself - building websites and several web applications since 1996 - Suffice to say, I have been slapped around by Google enough to remind me I need to play by their rules. (aka - Have had several sites deindexed/banned for being “overly aggressive” with SEO)



If you could provide an example - much appreciated.



MH

[quote name=‘JonahCoyote’]Great job guys, so instead of arguing over who said what and who can do what, why doesn’t somebody step up and offer some actual help? If you want money for it fine, say so, but if not and if its a simple solution and you feel generous enough to share, please do. End of story.[/QUOTE]

Uhm … step up and offer some acutal help? I just did that! (see above)



It can be very simple for most everyone (see AliasMatch) or simple for me (my way of saying easy for me but fairly complicated for most) and a lot of possibilities in between those two extremes.



Yes, I’ll give you a hand as well since you jumped in the conversation.


[quote name=‘NicheBuilder’]Thanks for clarifying - Just trying to understand the benefit of doing it that way versus setting a simple rewriterule to handle it permanently. In effect, it sounds like I will ultimately have 2 pages with the same content under 2 separate URI’s, no?[/QUOTE]

See my original first post (updated now with link to AliasMatch documentation)! :smiley:



Anyway, in a quick nutshell —



You would want to look more at remapping commands such as “Alias” or “AliasMatch” instead of “Redirect” or “RedirectMatch”.



You could also look at ReWrite commands but if you don’t have experience in those, they often overwhelm many people.



There are much more advanced techniques you can use involving some scripting, databases, or httpd.conf files and all that but I’m not even going to begin to try to explain that at the moment.



With respect to your question, the answer is “YES” you would have “2” pages bringing up the same content and that is entirely the point. If you redirect, the original page is trumped from indexing but if you allow both the old and new addresses to deliver the same content, you have additional mappable links and your original addresses remain fully in service (which means search engine searches to your old links are still valid as well which is advantageous by itself without even worrying about rank standings)



PS: Regarding your SEO / banned site comment – might be able to help there too. :wink:

[quote name=‘Spiral’]



With respect to your question, the answer is “YES” you would have “2” [/quote]



With a 301 you will not have a “duplicate” on Google.

Just thought I would step in and let you all know how I solved my issue. I DID look at what was recommended in the sense of the transparent redirect.



Since I DO know a little bit about htaccess, I chose that route with a 301.



Remember - my issue was an old dynamic url string that included index.php, which kinda screwed with CSC redirect. What ultimately worked was:



“Itemid=54” was the trailing end of the old url.

http://www.website.com/newcategory/?” is the redirect URL to the new category, with a ? to stop the old variable from displaying.



RewriteCond %{query_string} Itemid=54
RewriteRule (.*) http://www.website.com/newcategory/? [R=301,L]




Working like a charm.



Mark

[quote name=‘NicheBuilder’]Just thought I would step in and let you all know how I solved my issue. I DID look at what was recommended in the sense of the transparent redirect.



Since I DO know a little bit about htaccess, I chose that route with a 301.



Remember - my issue was an old dynamic url string that included index.php, which kinda screwed with CSC redirect. What ultimately worked was:



“Itemid=54” was the trailing end of the old url.

http://www.website.com/newcategory/?” is the redirect URL to the new category, with a ? to stop the old variable from displaying.



RewriteCond %{query_string} Itemid=54
RewriteRule (.*) http://www.website.com/newcategory/? [R=301,L]
Working like a charm.



Mark[/quote]



Well done! I said, there is not a optional method like 301 if you want to be fine by Google & Co.

NicheBuilder you are a wizard! What I or others could not accomplish in hours you solved in minutes… Your RewriteCond code above works perfectly for me for our old dyanmic URL’s - I’m going to post this to StackOverflow to let others know about this solution. I’m sure there must be easier ways to rewrite tons of dynamic URL’s but I don’t want to dig deeper and this works for me.



Thanks,

Jonah

[QUOTE]Well done! I said, there is not a optional method like 301 if you want to be fine by Google & Co[/QUOTE]



Agree completely! Like I said earlier in the post, I have tested the gray area of Google many times and lost… its just not worth it.



@ Jonah -



If you have a query string with a common ending that you want to direct to a single specific URL, just remove the unique id from your rewrite.



I only have a small handful to redirect (All old products are gone, so I am only interested in preserving categories, and directing all old cats and old products to the new categoriy pages) so I can do them manually, but if I had 200 products all ending in the Itemid=xxx, just remove the xxx portion and every string ending in itemid will redirect.



Ex:



RewriteCond %{query_string} Itemid=54



Traps SPECIFIC urls ending with “Itemid=53”



But:



RewriteCond %{query_string} Itemid=



Would catch EVERY url ending in “Itemid=”



Mark

Great Thread!



That said, I am still stuggling with the rule syntax and where it should be written to accomplish the following:



Old Store - [url]http://www.qualitypromosplus.com/agoracart55/agora.cgi[/url]

New Store - [url]http://www.qualitypromosplus.com/store/index.php[/url]



I want any page requests to any page in …/agoracart55/ to be redirected to the new store home page. And, I want to do this whether the old pages exist or not…



How is the rule written and where should the rule go?

@ Kvanlaar -



In your case, you should be able to use a simple 301 at the TOP of your htaccess file.


redirect 301 /agoracart55/ http://www.qualitypromosplus.com/store/



This will send EVERY request that contains the /agoracart55/ string to your homepage.



Mark

[quote name=‘kvanlaar’]Great Thread!



That said, I am still stuggling with the rule syntax and where it should be written to accomplish the following:



Old Store - [URL]http://www.qualitypromosplus.com/agoracart55/agora.cgi[/URL]

New Store - [URL]http://www.qualitypromosplus.com/store/index.php[/URL]



I want any page requests to any page in …/agoracart55/ to be redirected to the new store home page. And, I want to do this whether the old pages exist or not…



How is the rule written and where should the rule go?[/quote]



This should work:


RewriteEngine on
RewriteCond %{query_string} /agoracart55/
RewriteRule (.*) http://www.yourdomain.xy/? [R=301,L]

Nice… …the file structure is something like this



www.qualitypromosplus.com

/agoracart55

/store



I am assuming the redirect would be in the htaccess at the root as opposed to the htaccess files that exist in the subfolders???



Also I notice you have 301 in the rewriterule…does this mean the redirect will occur only if the page is not found?? Or will it redirect even if the page exists in /agoracart55/



thanks for your timely help!

[quote name=‘indy0077’]This should work:


RewriteEngine on
RewriteCond %{query_string} /agoracart55/
RewriteRule (.*) http://www.yourdomain.xy/? [R=301,L]
[/QUOTE]



Doesn’t RewriteCond only look at the string following the ? mark in the URL…I am trying to understand this all…



[url]http://www.qualitypromosplus.com/agoracart55/agora.cgi?p_id=00001[/url]



I thought it only looked at p_id=00001