Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!



Photo
- - - - -

Redirecting Old Domain To New With Different Paths


  • Please log in to reply
11 replies to this topic

#1 WesMcDermott

WesMcDermott

    HR 2

  • Members
  • PipPip
  • 42 posts
  • Location:Manchester, UK

Posted 29 October 2010 - 11:37 AM

I'm struggling to get my head round this bit of the site transfer process. I've been talking with my host about htaccess and redirects and after putting together this htaccess to redirect my old site to my new site they've decided that it's no longer part of their support. Uploaded the htaccess and nothing, apart from the first rule in the code below. The link without the www redirects the rest are useless.

Would appreciate any feedback on why this may be happening and what I can do to fix the problem. Thanks.

Here's a snippet of the htaccess at the moment:

CODE
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^weightgain4you\.com$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/diet-and-nutrition.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/muscle-building-nutrition [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/Weight-Gain-Tips.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/articles [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/HomeGymEquipment.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/home-gym-reviews [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/directory.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/related-resources [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/training-equipment-resources.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/related-resources [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/training-directories.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/related-resources [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/Weight-Training-Nutrition.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/muscle-building-nutrition [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/Basic-Nutrition.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/nutrition-...nd-build-muscle [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/Stop_Wasting_Your_Protein.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/sean-nalew...wasting-protein [R=301,L]

RewriteCond %{HTTP_HOST} ^http://www.weightgain4you.com/Gain_Muscle_By_Eating_No_Protein.php$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com/nutrition-...without-protein [R=301,L]


#2 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 968 posts
  • Location:Michigan USA

Posted 29 October 2010 - 01:04 PM

QUOTE
Uploaded the htaccess and nothing, apart from the first rule in the code below. The link without the www redirects the rest are useless.

Which is exactly what you told it to do, Wes.

See the [R=301,L] tag? The L essentially stands for LAST, meaning "if this rule fires, don't bother processing any more directives." It's used to save processing once a match is found and you know no other match is possible. On most of your directives, the L probably makes sense. On the first two directives, however, it makes everything following superfluous.


#3 WesMcDermott

WesMcDermott

    HR 2

  • Members
  • PipPip
  • 42 posts
  • Location:Manchester, UK

Posted 30 October 2010 - 04:35 AM

Ron, thanks for that!

I don't really need to spell it out but I'm not a genius when it comes to mod_rewrite. I'm trying to learn more about it.

With the regards the [R=301,L] tag, what do I replace it with, just [R=301]? Also, the L tag, does this apply only to directives that contain the final path of url, ie. www.muscle-gain-tips.com/nutrition-articles/stop-wasting-your-protein whereas if the url www.muscle-gain-tips.com/nutrition-articles contained the L any directives that contained anything after /nutrition-articles would not be redirected?

I think that's what I meant to say!

Cheers,
Wes

#4 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 968 posts
  • Location:Michigan USA

Posted 30 October 2010 - 07:43 AM

QUOTE
With the regards the [R=301,L] tag, what do I replace it with, just [R=301]?

Yes.

QUOTE
Also, the L tag, does this apply only to directives that contain the final path of url ...

It applies to any RewriteRule. It does not apply to Conditions.

QUOTE
I'm trying to learn more about it.

That should, of course, be your ultimate goal, Wes. While most people don't need to know everything there is to know about mod_rewrite, they should at the very least research every single command, tag, or directive before they copy and paste it into their .htaccess file. And I always recommend testing methodically, one step at a time, rather than throwing all the redirects into the soup at once. It's not rocket science, but it IS science.

That being said, I would suggest your next course should be to research the HTTP_HOST part of your rewrite condition. You're using it appropriately in your first two blocks, because you actually are interested in what host name is being called. You are not using it appropriately in any of the other blocks, however. Even when you remove the L tag, those other blocks will never fire because the rewrite condition will never be met.

Hint: You need to use mod_rewrite on your first two blocks. You really don't need the power (or complexity) of mod_rewrite, however, just to redirect from one page to another page. You might want to look up the REWRITE directive (which is part of mod_alias, not mod_rewrite) and use that to redirect simple pages. Put in your redirects one at a time (and place them above your mod_rewrite directives so they fire first) and you should be able to work it out pretty quickly. And when you're done, you'll actually understand what each line is meant to accomplish.




#5 WesMcDermott

WesMcDermott

    HR 2

  • Members
  • PipPip
  • 42 posts
  • Location:Manchester, UK

Posted 01 November 2010 - 05:23 AM

Ron,

I've edited the htaccess so i'm using both mod_rewrite for the homepage redirects and mod_alias for each specific page. Both homepage redirects are redirecting correctly and the very first rule is redirecting correctly aswell however, the rest of the rules are going to the homepage?

[codebox]AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Options +FollowSymLinks
RewriteEngine On
Redirect 301 /diet-and-nutrition.php http://www.muscle-ga...lding-nutrition

Redirect 301 /Weight-Gain-Tips.php http://www.muscle-ga...ps.com/articles

Redirect 301 /weight-training-programs-to-build-muscle.php http://www.muscle-gain-

tips.com/muscle-building-programs

Redirect 301 /HomeGymEquipment.php http://www.muscle-ga...ome-gym-reviews

Redirect 301 /directory.php http://www.muscle-ga...lated-resources

Redirect 301 /training-equipment-resources.php http://www.muscle-ga...lated-resources

Redirect 301 /training-directories.php http://www.muscle-ga...lated-resources

Redirect 301 /Weight-Training-Nutrition.php http://www.muscle-ga...uscle-building-

nutrition

Redirect 301 /Basic-Nutrition.php http://www.muscle-ga...ticles/food-to-

eat-to-gain-weight-and-build-muscle

Redirect 301 /Stop_Wasting_Your_Protein.php http://www.muscle-ga...nalewanyj/stop-

wasting-protein

Redirect 301 /Gain_Muscle_By_Eating_No_Protein.php http://www.muscle-ga....com/nutrition-

articles/gain-muscle-without-protein

Redirect 301 /Lunch.php http://www.muscle-ga...n/recipes/lunch

Redirect 301 /Snacks.php http://www.muscle-ga.../recipes/snacks

Redirect 301 /Supplement-Reviews/Creatine.php http://www.muscle-ga...s.com/creatine-

supplements

Redirect 301 /Supplement-Reviews/Fish-Oil.php http://www.muscle-ga...s.com/fish-oil-

supplements

Redirect 301 /Supplement-Reviews/WeightGainers.php http://www.muscle-ga.../weight-gainers

Redirect 301 /Weight-Training-Articles/pre-workout-nutrition.php http://www.muscle-gain-

tips.com/sean-nalewanyj/proper-pre-workout-nutrition

Redirect 301 /Weight-Training-Articles/muscle-without-fat.php http://www.muscle-gain-

tips.com/vince-delmonte/can-you-gain-muscle-without-gaining-fat

Redirect 301 /Weight-Training-Articles/Vince-Delmonte-Interview.php http://www.muscle-gain-

tips.com/vince-delmonte/interview-2

Redirect 301 /Weight-Training-Articles/Marc-C.David.php http://www.muscle-gain-tips.com/marc-

david

Redirect 301 /Weight-Training-Articles/The-Musclehead.php http://www.muscle-gain-tips.com/vince-

delmonte

Redirect 301 /Weight-Training-Articles/Training.php http://www.muscle-ga...ps.com/articles

Redirect 301 /Weight-Training-Articles/Motivational.php http://www.muscle-ga...ps.com/articles

Redirect 301 /Weight-Training-Articles/Videos.php http://www.muscle-ga...ps.com/articles

Redirect 301 /Weight-Training-Articles/Bodybuilding-On-A-Budget.php http://www.muscle-gain-

tips.com/marc-david/bodybuilding-on-a-budget

Redirect 301 /Weight-Training-Articles/Multi-vitamins.php http://www.muscle-gain-tips.com/sean-

nalewanyj/multi-vitamins-are-they-worth-the-bother

Redirect 301 /Weight-Training-Articles/Gym-Goer-Pt2.php http://www.muscle-ga...ps.com/articles

Redirect 301 /Weight-Training-Articles/Sore-Muscles.php http://www.muscle-gain-tips.com/nick-

nilsson/can-i-train-with-sore-muscles

Redirect 301 /Weight-Training-Articles/Gain-25-Pounds.php http://www.muscle-gain-tips.com/nick-

nilsson/how-i-gained-20-pounds-in-7-days

Redirect 301 /Weight-Training-Articles/Travel-Training.php http://www.muscle-gain-

tips.com/articles/training-tips-whilst-travelling

Redirect 301 /Weight-Training-Articles/Gym-Equipment-To-Build-Muscle.php http://www.muscle-gain-

tips.com/articles/home-gym-equipment-to-build-muscle

Redirect 301 /Weight-Training-Articles/Teen-Bodybuilding-101.php http://www.muscle-gain-

tips.com/articles/building-muscle-for-teens

Redirect 301 /Weight-Training-Articles/Protein-FAQ.php http://www.muscle-gain-

tips.com/nutrition-articles/protein-faqs

Redirect 301 /Weight-Training-Articles/Supplement-Bandwagon.php http://www.muscle-gain-

tips.com/nick-nilsson/the-truth-about-supplement-ads

Redirect 301 /Weight-Training-Programs/No-Nonsense-Muscle-Building.php http://www.muscle-gain-

tips.com/muscle-building-programs/no-nonsense-muscle-building-review

Redirect 301 /Weight-Training-Programs/Intermediate-Experts.php http://www.muscle-gain-

tips.com/muscle-building-programs

Redirect 301 /Weight-Training-Programs/MuscleHeads-Guide.php http://www.muscle-gain-

tips.com/muscle-building-programs

Redirect 301 /Weight-Training-Programs/Bodybuilding-Revealed.php http://www.muscle-gain-

tips.com/muscle-building-programs/bodybuilding-revealed-review

Redirect 301 /Weight-Training-Programs/Optimum-Anabolics.php http://www.muscle-gain-

tips.com/muscle-building-programs

Redirect 301 /Weight-Training-Programs/Homemade-Supplements.php http://www.muscle-gain-

tips.com/muscle-building-programs

Redirect 301 /Weight-Training-Programs/Truth-About-Abs.php http://www.muscle-gain-

tips.com/muscle-building-programs/the-truth-about-abs-review

Redirect 301 /Weight-Training-Tips/Arms-Tips.php http://www.muscle-ga...ps.com/articles

Redirect 301 /Weight-Training-Tips/Back-Shoulder-Tips.php http://www.muscle-gain-

tips.com/articles

Redirect 301 /Weight-Training-Tips/Other-Tips.php http://www.muscle-ga...ps.com/articles

Redirect 301 /Weight-Training-Tips/Killer-Triceps.php http://www.muscle-gain-

tips.com/articles/how-to-build-killer-triceps

Redirect 301 /Weight-Training-Tips/Want-A-Big-Bench-Press.php http://www.muscle-gain-

tips.com/articles/how-to-get-a-big-bench-press

Redirect 301 /Weight-Training-Tips/Improve-Leg-Curls.php http://www.muscle-gain-

tips.com/articles/how-to-improve-your-leg-curls

Redirect 301 /Weight-Training-Tips/Breathe-Backwards.php http://www.muscle-gain-

tips.com/articles/breathing-backwards-to-improve-training-performance

Redirect 301 /home-gym-equipment-reviews/body-solid/EXM-1500S.php http://www.muscle-gain-

tips.com/body-solid-reviews/exm-1500

Redirect 301 /home-gym-equipment-reviews/body-solid/Power-Center-Smith-Machine.php

http://www.muscle-ga...achine-home-gym

Redirect 301 /home-gym-equipment-reviews/bowflex.php http://www.muscle-ga...ps.com/bowflex-

reviews

Redirect 301 /home-gym-equipment-reviews/bowflex/xtreme-2.php http://www.muscle-gain-

tips.com/bowflex-reviews/xtreme-2

Redirect 301 /home-gym-equipment-reviews/bowflex/blaze.php http://www.muscle-gain-

tips.com/bowflex-reviews/blaze

Redirect 301 /home-gym-equipment-reviews/powertec.php http://www.muscle-ga...s.com/powertec-

reviews

Redirect 301 /home-gym-equipment-reviews/powertec/multi-leverage-system.php http://www.muscle-

gain-tips.com/powertec-reviews/multi-leverage-system

Redirect 301 /home-gym-equipment-reviews/bodycraft.php http://www.muscle-gain-

tips.com/bodycraft-reviews

Redirect 301 /home-gym-equipment-reviews/bodycraft/galena.php http://www.muscle-gain-

tips.com/bodycraft-reviews/galena

Redirect 301 /home-gym-equipment-reviews/yukon/caribou-3-system.php http://www.muscle-gain-

tips.com/yukon-reviews/caribou-3-system

Redirect 301 /home-gym-equipment-reviews/as-seen-on-tv.php http://www.muscle-gain-tips.com/as-

seen-on-tv-reviews

Redirect 301 /home-gym-equipment-reviews/as-seen-on-tv/lifeline.php http://www.muscle-gain-

tips.com/as-seen-on-tv-reviews/lifeline

Redirect 301 /home-gym-equipment-reviews/as-seen-on-tv/weider-crossbow.php http://www.muscle-

gain-tips.com/as-seen-on-tv-reviews/weider-crossbow

RewriteCond %{HTTP_HOST} ^weightgain4you\.com$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com [R=301]

RewriteCond %{HTTP_HOST} ^www.weightgain4you.com$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com [R=301,L][/codebox]

#6 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 968 posts
  • Location:Michigan USA

Posted 01 November 2010 - 08:39 AM

That certainly looks a lot better, Wes. At a glance, nothing jumps out as inherently wrong, at least nothing that would explain the symptoms you've described. At what point did directives start failing? That can often point a finger towards the cause. You did enter and test one step at a time, right? smile.gif

(While it shouldn't affect what you're trying to do, Wes, your target URL should be fully qualified -- meaning, specifically, that directories should all have a trailing slash. In other words, http://example.com/directory should always be http://example.com/directory/ so the server doesn't have to first look for a file named directory. Worse than just adding unnecessary work to your server, there are still a lot of servers out there configured to add the slash for you, which will result in it issuing a 302 redirect that can step all over your 301. Always adding the trailing slash is a good habit to build and maintain.)


#7 WesMcDermott

WesMcDermott

    HR 2

  • Members
  • PipPip
  • 42 posts
  • Location:Manchester, UK

Posted 01 November 2010 - 09:07 AM

QUOTE(Ron Carnell @ Nov 1 2010, 02:39 PM) View Post
That certainly looks a lot better, Wes. At a glance, nothing jumps out as inherently wrong, at least nothing that would explain the symptoms you've described. At what point did directives start failing? That can often point a finger towards the cause. You did enter and test one step at a time, right? smile.gif


I tested it after the first rule then uploaded a htaccess file with just the top 2 rules. The 1st rule fires correctly, the 2nd shoots to the homepage of muscle-gain-tips.com.

QUOTE
(While it shouldn't affect what you're trying to do, Wes, your target URL should be fully qualified -- meaning, specifically, that directories should all have a trailing slash. In other words, http://example.com/directory should always be http://example.com/directory/ so the server doesn't have to first look for a file named directory. Worse than just adding unnecessary work to your server, there are still a lot of servers out there configured to add the slash for you, which will result in it issuing a 302 redirect that can step all over your 301. Always adding the trailing slash is a good habit to build and maintain.)


My urls are displayed without the / does this rule still apply?




#8 WesMcDermott

WesMcDermott

    HR 2

  • Members
  • PipPip
  • 42 posts
  • Location:Manchester, UK

Posted 01 November 2010 - 09:19 AM

QUOTE
I tested it after the first rule then uploaded a htaccess file with just the top 2 rules. The 1st rule fires correctly, the 2nd shoots to the homepage of muscle-gain-tips.com.


Scrap that, it doesn't fire correctly on any of the mod_alias redirects. Every redirect is going to the homepage.

#9 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 968 posts
  • Location:Michigan USA

Posted 01 November 2010 - 05:16 PM

QUOTE
My urls are displayed without the / does this rule still apply?

Yes. Your server isn't issuing a 302 like some will, but it's still doing extra work that doesn't need to be done. And if you move to another server six months from now? Like I said, using trailing slashes is simply a good habit to establish.

QUOTE
Scrap that, it doesn't fire correctly on any of the mod_alias redirects.

So something was wrong with your initial tests, it seems.

Again, the only way to track a bug is methodically. Put in your first redirect and then test it. Put in your second redirect and then test BOTH. Repeat until something fails. The last thing you entered logically caused it to fail. Make sense?

'Least that's what I'd do . . .


#10 WesMcDermott

WesMcDermott

    HR 2

  • Members
  • PipPip
  • 42 posts
  • Location:Manchester, UK

Posted 02 November 2010 - 05:40 AM

QUOTE(Ron Carnell @ Nov 1 2010, 11:16 PM) View Post
Yes. Your server isn't issuing a 302 like some will, but it's still doing extra work that doesn't need to be done. And if you move to another server six months from now? Like I said, using trailing slashes is simply a good habit to establish.


So something was wrong with your initial tests, it seems.

Again, the only way to track a bug is methodically. Put in your first redirect and then test it. Put in your second redirect and then test BOTH. Repeat until something fails. The last thing you entered logically caused it to fail. Make sense?

'Least that's what I'd do . . .


Hi Ron,

It seems as though the mod_alias rules aren't firing. This is the code I currently have up:

[codebox]AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Options +FollowSymLinks
RewriteEngine On
Redirect 301 /diet-and-nutrition.php http://www.muscle-ga...lding-nutrition

Redirect 301 /Weight-Gain-Tips.php http://www.muscle-ga...ps.com/articles

RewriteCond %{HTTP_HOST} ^weightgain4you\.com$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com [R=301]

RewriteCond %{HTTP_HOST} ^www.weightgain4you.com$ [NC]
RewriteRule ^(.*)$ http://www.muscle-gain-tips.com [R=301]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^seobyhand.co.uk/?$ "http\:\/\/www\.seobyhand\.co\.uk" [R=301,L][/codebox]

As you can see I have just 2 mod_alias rules up. These are redirecting to the homepage not the pages specified. Could this be an issue with the server or is it an actual issue with the htaccess do you think?

#11 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 968 posts
  • Location:Michigan USA

Posted 02 November 2010 - 06:01 AM

Conceivably, yea, it could be an issue with the server. No two machines ever seem to be configured exactly the same and it's certainly possible, I suppose, that mod_alias isn't being loaded. You're hosting company could give you the definitive answer.

I already told you what I would do. Not much else I can add, I guess.


#12 WesMcDermott

WesMcDermott

    HR 2

  • Members
  • PipPip
  • 42 posts
  • Location:Manchester, UK

Posted 02 November 2010 - 06:55 AM

QUOTE(Ron Carnell @ Nov 2 2010, 12:01 PM) View Post
Conceivably, yea, it could be an issue with the server. No two machines ever seem to be configured exactly the same and it's certainly possible, I suppose, that mod_alias isn't being loaded. You're hosting company could give you the definitive answer.

I already told you what I would do. Not much else I can add, I guess.


Ok thanks for your input Ron. I've gone about things exactly how you've said so far, just awaiting a reply from my host to see what the issue with these mod_alias rules is.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

We are now a read-only forum.
 
No new posts or registrations allowed.