iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
IT Discussion Forum Having IT issues? Got IT questions? Who doesn't? If you can't get your Apache to work with your MySQL or your php is choking on your ODBC... Let's see if we can help you come up with some ideas.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2008, 01:08 AM
WebProWorld Pro
 
Join Date: Jul 2004
Location: Irvine, CA
Posts: 125
spenland RepRank 0
Default Need help with 301 redirect and mod_rewrite

I just changed the DNS to launch a new website and I need a little help. I've done plenty of 301 redirects before for individual files, but how do you do a redirect for an entire folder? Also many of the pages on the old site had urls like 'news.php?id=4" Is it possible to do a redirect for any URL containing 'news.php' id, and a number to the home page?

I appreciate any help.
Reply With Quote
  #2 (permalink)  
Old 12-01-2008, 11:18 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,629
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Need help with 301 redirect and mod_rewrite

An entire folder can be redirected rather easily. For example, to redirect domain.tld/oldfolder/file.html to domain.tld/newfolder/file.html, you would use the following code in your .htaccess file:
Code:
RedirectMatch ^/oldfolder/(.*) http://domain.tld/newfolder/$1
I am not sure, however, if that will properly redirect query strings as well. If it doesn't, you may need to use mod_rewrite.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #3 (permalink)  
Old 12-01-2008, 11:28 AM
WebProWorld Pro
 
Join Date: Dec 2007
Location: Brussels, Belgium
Posts: 163
Jean-Luc RepRank 2
Default Re: Need help with 301 redirect and mod_rewrite

I would try this :
Code:
RedirectPermanent /old_folder/ http://www.new_domain.com/new_folder/
RedirectPermanent /news.php http://www.new_domain.com/?
Jean-Luc
__________________
Checking redirects made easy | | Professional AWStats Services
Reply With Quote
  #4 (permalink)  
Old 12-02-2008, 11:00 PM
AjiNIMC's Avatar
WebProWorld Pro
 
Join Date: Aug 2004
Location: India
Posts: 279
AjiNIMC RepRank 0
Default Re: Need help with 301 redirect and mod_rewrite

Redirection using .htaccess is quite simple, keep 3 things in mind:

1) Do you have POST variables to these old urls, while posting a variables, it will lose values.
2) Make sure you don't lose the value of links that old urls had but doing proper redirection.
3) Links from internal pages needs to change to new urls as fast as possible to improve user experience.


Lets take things one by one:

news.php?id=4 , if the new urls in a pattern like something-4.html, it can be done at .htaccess like
RewriteRule news.php?id=(.*) /foldername/$1.html [R=301,L]

Now if the new URLs doesn't have a pattern
RewriteRule news.php?id=(.*) /redirect/index.php?id=$1 [L]

Now the redirect/index.php can get the new url from the DB and do a 301 redirection.


Folder redirection can happen like
RewriteRule ^/oldfolder/(.*) http://domain.tld/newfolder/$1

More matching and complex things can be done with referring variables from condition comparisons. Do let me know if you need more help.

Regards,
Aji Issac
__________________
Be web educated - Client education series - Let not your SEO company cheat you. When they screw your website, they lose one client and you everything.
Reply With Quote
  #5 (permalink)  
Old 12-03-2008, 05:46 AM
TrafficProducer's Avatar
WebProWorld 1,000+ Club
 
Join Date: Jul 2003
Location: United Kingdom
Posts: 1,638
TrafficProducer RepRank 3TrafficProducer RepRank 3
Default Re: Need help with 301 redirect and mod_rewrite

You may find some help here, (above ^^ notes looks like good tips):-

Apache open-source software and Apache Servers. Mod Rewrite.

and

.htaccess Files and .htaccess Help. How use to .htaccess

Reply With Quote
  #6 (permalink)  
Old 12-04-2008, 05:17 PM
WebProWorld Pro
 
Join Date: Jul 2004
Location: Irvine, CA
Posts: 125
spenland RepRank 0
Default Re: Need help with 301 redirect and mod_rewrite

Great thanks for the tips guys!

AjiNIMC, I have one question about your suggestion. If I want to do as you suggested with this example:

RewriteRule ^/oldfolder/(.*) http://domain.tld/newfolder/$1

what does the '$1' do in this example? Is it a variable of some type? Can I leave it out?

Thanks!
Reply With Quote
  #7 (permalink)  
Old 12-04-2008, 05:24 PM
WebProWorld Pro
 
Join Date: Jul 2004
Location: Irvine, CA
Posts: 125
spenland RepRank 0
Default Re: Need help with 301 redirect and mod_rewrite

Also, what if I want to create a catch all for any old pages that follow the news.php?id=* format?

i.e.

news.php?id=anything forwards to www.mywebsite.com/news/
Reply With Quote
  #8 (permalink)  
Old 12-04-2008, 06:45 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,629
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Need help with 301 redirect and mod_rewrite

Quote:
Originally Posted by spenland View Post
Great thanks for the tips guys!

AjiNIMC, I have one question about your suggestion. If I want to do as you suggested with this example:

RewriteRule ^/oldfolder/(.*) http://domain.tld/newfolder/$1

what does the '$1' do in this example? Is it a variable of some type? Can I leave it out?

Thanks!
Whatever is in parenthesis in the first section is put into a numbered variable in the destination. So for

RewriteRule /(.*)/(.*).html showpage?subject=$1&article=$2

$1 would correspond to the first .* and $2 would correspond to the second.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
.htaccess and mod_rewrite inertia IT Discussion Forum 3 11-16-2007 09:43 AM
How to do a mod_rewrite? watto Web Programming Discussion Forum 2 06-02-2007 01:17 PM
mod_rewrite watto Services for Sale/Hire 0 11-08-2005 08:47 PM
I Hate mod_rewrite!!! icb01co2 Web Programming Discussion Forum 1 05-18-2005 01:04 AM
Alternate to mod_rewrite? cyberious Search Engine Optimization Forum 3 05-31-2004 02:25 AM


All times are GMT -4. The time now is 07:35 PM.



Search Engine Optimization by vBSEO 3.3.0