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!


Sponsored Content

 

 
 

Photo
- - - - -

Cant Redirect Dynamic Urls To New Site


  • Please log in to reply
13 replies to this topic

#1 tyggis

tyggis

    HR 4

  • Active Members
  • PipPipPipPip
  • 169 posts

Posted 10 July 2008 - 06:32 PM

I am moving some pages to a new site and need to redirect some pages 301. I try in htaccess, but this is not working:

CODE
Redirect 301 /arreler/bss.php?id=295&recipe_title=Ofte_blank%3F http://www.mydomain23.org/ofte-blank%3F


This is working:

CODE
Redirect 301 /arreler/bss.php http://www.mydomain23.org/ofte-blank%3F


So how can I redirect that dynamic urls 301?

Thanks smile.gif

#2 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 10 July 2008 - 07:32 PM

You can't put variables in a seed part of a mod_alias redirect. The Redirect 301 method uses mod_alias. It simply wasn't designed to analyze variables like you're asking it to.

You'd need to use the mod_rewrite method of redirecting instead. Assuming mod_rewrite is enabled on your server and based upon what you've posted above the following should do the trick.

CODE
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/arreler/bss\.php
RewriteRule ^arreler/(.*)$ http://www.mydomain23.org/$1 [R=301,L]


#3 tyggis

tyggis

    HR 4

  • Active Members
  • PipPipPipPip
  • 169 posts

Posted 11 July 2008 - 11:18 AM

Thanks Randy for taking the time to help me. smile.gif
I am a novice when it comes to this redirect stuff. Can you please write how the full code for the 301 redirecting of

CODE
http://www.mydomain111.org/arreler/bss.php?id=295&recipe_title=Ofte_blank%3F

to
CODE
http://www.mydomain23.org/ofte-blank%3F


Thanks again.

#4 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 11 July 2008 - 12:28 PM

Well, a couple of things before I just dive on in.

In your orignal URL you have an "id" variable that has a value of 295. Does this need to be passed through the redirect at all? Are only those urls with an id of 295 going to be redirected? What happens if the original url has an id of 294, does it need to be redirected too? To the same final url, or a different one?

Second, what's with the %3F? That's the URLencded equilvalent for a question mark. Why is that in the location it's at in the original url at all? And do you need to account for it being there or not being there? I have a feeling there are other (not exaxctly correct) rewrites in the mix somewhere, so adding more may cause conflicts.

Does the %3F question mark need to be there on the final url at all? It would normally be considered bad form to end off a url with a question mark when there are no variables used.

#5 tyggis

tyggis

    HR 4

  • Active Members
  • PipPipPipPip
  • 169 posts

Posted 13 July 2008 - 08:49 AM

The number 295 is unique for that page. Its the article number 295 on the site and all pages have different numbers.

The %3F is the end of the name of the article. The article name is formed as a question. The other articles does not have %3F in the end.

Another example of a page I need to redirect is:

CODE
http://www.mydomain111.org/arreler/bss.php?id=302&recipe_title=Pensjon


to

CODE
http://www.mydomain23.org/Pensjon


#6 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 13 July 2008 - 05:04 PM

Okay. So you won't need the id variable value at all then?

Untested, but should work.
CODE
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/arreler/bss\.php
RewriteCond %{QUERY_STRING} recipe_title=(.*)
RewriteRule ^(.*)$ http://www.mydomain23.org/%1? [R=301,L]


Two quick things...

The question mark at the end of the new domain part of the rewrite rule really does need to be there even though it may look like a typo. That's how you suppress the natural action of appending the orignal query string back into the new url address.

And second, note that the above will not change an character case from the original recipe_title value at all. I don't know if you'll need it or not, but Case is not something .htaccess can do well or easily. Even if only the first letter of the variable value might be capped you'd still need what amounts to a separate rewrite rule for each letter of the alphabet. There are other ways to handle case, but for those you'll need access to the actual Apache configuration file for the domain. So hopefully you're wanting to carry the same character case straight on through.

#7 tyggis

tyggis

    HR 4

  • Active Members
  • PipPipPipPip
  • 169 posts

Posted 13 July 2008 - 06:12 PM

Thanks a lot Randy, this works very well. smile.gif
To well in a way because now all the articles of the site get redirected to the new site. My plan was to redirect just 150 of them, but I suppose that is not possible?

#8 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 13 July 2008 - 09:21 PM

QUOTE
My plan was to redirect just 150 of them, but I suppose that is not possible?


Not without adding in a bunch of RewriteCond statements. Either for the articles you want to redirect or excluding those you don't want to redirect.

#9 tyggis

tyggis

    HR 4

  • Active Members
  • PipPipPipPip
  • 169 posts

Posted 15 July 2008 - 04:41 PM

Would that cause a server to work to much?
Can you please give me an example on how that code would look like if I added that bunch of RewriteCond statements?

#10 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 15 July 2008 - 06:23 PM

Well, it's not strictly a question of the server working to much. Not as much as it is the server having to parse through every single line of the .htaccess file for every single page load.

You have one example above that redirects every page. It takes 2 Rewrite Conditions and 1 Rewrite Rule to make it happen. In order to do such a positive match with every page you wanted to redirect and do it on a page by page basis it's going to require 3 lines each. Or if you went with a negative match it's going to require at least 1 negative Rewriterule for each recipe_title you want to exclude, then the blanket redirect.

The crux of the matter is you really don't want to end up with a 100+ line, fairly complex .htaccess mod_rewrite if you can keep from it. Because every single page load is going to cause the .htaccess to fire. Whether the page request has anything to do with your redirect or not. It would cause your entire site and server to slow down. And some host frown greatly upon overuse of .htaccess.

#11 Sarah

Sarah

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 391 posts
  • Location:Kent

Posted 16 July 2008 - 05:55 AM

Not answering as such but asking a quick Q based around this which might provide an answer - can you redirect an entire old server file to the new server file, waiting for the old server file pages to get dropped from the index and the new server file pages to be indexed?

Or should I just sit down quietly in the corner again Randy?

#12 tyggis

tyggis

    HR 4

  • Active Members
  • PipPipPipPip
  • 169 posts

Posted 16 July 2008 - 06:06 AM

Yes, I found this nice thread about that:
http://www.highranki...showtopic=24888

The thing here is that I have a site with about 2000 articles. The articles are not to much visited so its not very important to me to keep them, but some of them have some nice inlinks from other sites that found them useful and I want to keep the "link juice". There is about 150 articles I want to move and the reason that I want a 301 redirect is to keep the inlinks. I mean, I could just delete the articles on the old page, but then I would lose the inlinks.
With your solution above here all the 2000 articles are redirected to the new site, most of them will not have a new page to go to of course so they will be redirected to the home page of the new site. Will the home page of the new site then gain from all the "link juice" from the old pages that are redirected?

#13 Sarah

Sarah

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 391 posts
  • Location:Kent

Posted 16 July 2008 - 07:33 AM

QUOTE(tyggis @ Jul 16 2008, 12:06 PM) View Post
With your solution above here all the 2000 articles are redirected to the new site, most of them will not have a new page to go to of course so they will be redirected to the home page of the new site. Will the home page of the new site then gain from all the "link juice" from the old pages that are redirected?


You wouldn't necessarily have redirect to the home page - you can redirect to any page you want to, the most relevant page is always best and the juice should be passed on.

Can you redirect folders and then have a seperate set of redirects for specific pages within that folder?

In the case of the articles that currently exist that don't have a new page, I guess you could categorise your articles on the new site and take the visitor to the best category page for them to choose a.n. other article, or you could just put up those articles with in links up again under a new URL and do the seperate redirects - I take it the new URLs are necessary?



#14 tyggis

tyggis

    HR 4

  • Active Members
  • PipPipPipPip
  • 169 posts

Posted 18 July 2008 - 01:25 PM

Good idea with the folders, but all the folders also have a "?" before them so I cant do that.
So I cant see any other solution for this than to redirect all the articles to the main page of the new site. Curious to see how the "link juice" will work when I do that.
But thanks a lot for the help. Its not in vain, Randys solution comes to good use for another site I have.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users