WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-29-2007, 07:48 PM
WebProWorld Member
 

Join Date: Sep 2003
Posts: 55
vintagedge RepRank 0
Default 301 redirect code not working

I have been trying to search for information on the code for a 301 redirect. I have included this in my .htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

I am trying to redirect the non www site to the www site.
When I put this up and check the browser using http://mysite.com it goes to:
http://www.mysite.com/mysite/index.html

I am also trying to redirect (both www and non www)
www.oldsite.com to www.mysite.com

I don't know if this is the place to ask but I am desperate.
__________________
Original Vintage designed t-shirts at http://www.vintagedge.com
Reply With Quote
  #2 (permalink)  
Old 07-29-2007, 08:29 PM
sands's Avatar
WebProWorld Veteran
 

Join Date: Sep 2005
Location: Kerala, India
Posts: 397
sands RepRank 1
Default Re: 301 redirect code not working

Check this site: Best Apache .htaccess tips, tricks, hacks, and examples.
__________________
My Nook | My Biz
Reply With Quote
  #3 (permalink)  
Old 07-30-2007, 02:07 PM
WebProWorld Pro
 

Join Date: May 2007
Location: DataCenter
Posts: 174
hostBrain RepRank 1
Default Re: 301 redirect code not working

Try this code, it has worked for me:

Quote:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.(.*)
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
__________________
----Don't Call Me Brian----
Reply With Quote
  #4 (permalink)  
Old 07-30-2007, 04:13 PM
WebProWorld Pro
 

Join Date: May 2006
Location: Arizona, USA
Posts: 194
jrb@w3f.com RepRank 0
Default Re: 301 redirect code not working

Quote:
Originally Posted by hostBrain View Post
Try this code, it has worked for me:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.(.*)
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

Yeah, that is the trick, also notice it does mysite.net to www.mysite.com as well.

But you forgot the [NC] which means to ignore case:

--------------------------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.(.*) [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
--------------------------
__________________
http://MADEinUSA.org and others.

Last edited by jrb@w3f.com : 07-30-2007 at 04:16 PM.
Reply With Quote
  #5 (permalink)  
Old 07-30-2007, 07:41 PM
WebProWorld New Member
 

Join Date: Jul 2003
Location: Omaha, NE
Posts: 22
wetchman RepRank 0
Default Re: 301 redirect code not working

This is great for Apache - any best practices anybody would like to share for implementing this on IIS?
__________________
BW - Orajen Group, Inc.
Web Design and Development
http://www.orajen.com/
Reply With Quote
  #6 (permalink)  
Old 07-30-2007, 10:24 PM
WebProWorld Member
 

Join Date: Sep 2003
Posts: 55
vintagedge RepRank 0
Default Re: 301 redirect code not working

Thanks for the replies.

I have found that it is a requirement to to have mod_rewrite enabled on Apache - anybody with any idea how to do that?

It is running on a Mac OS X Server.

I am switching service providers for DSL so service is up and down so sorry I didn't respond to these helpful suggestions earlier.
__________________
Original Vintage designed t-shirts at http://www.vintagedge.com
Reply With Quote
  #7 (permalink)  
Old 07-30-2007, 10:33 PM
WebProWorld Member
 

Join Date: Sep 2003
Posts: 55
vintagedge RepRank 0
Default Re: 301 redirect code not working

I tried the above and it did not work it switches to
www.mysite.com/mysite

It seems that it is looking for a folder that is not there maybe?
__________________
Original Vintage designed t-shirts at http://www.vintagedge.com
Reply With Quote
  #8 (permalink)  
Old 07-31-2007, 12:17 AM
WebProWorld Pro
 

Join Date: May 2007
Location: DataCenter
Posts: 174
hostBrain RepRank 1
Default Re: 301 redirect code not working

thanks jrb@w3f.com, i did forget that - nice catch
Quote:
Originally Posted by vintagedge View Post
I have found that it is a requirement to to have mod_rewrite enabled on Apache - anybody with any idea how to do that?
mod_rewrite needs to be enabled in apache's config file
__________________
----Don't Call Me Brian----
Reply With Quote
  #9 (permalink)  
Old 07-31-2007, 09:34 AM
WebProWorld Member
 

Join Date: Sep 2003
Posts: 55
vintagedge RepRank 0
Default Re: 301 redirect code not working

Thanks. Can you tell me how to do that? My service provider is unsure.
__________________
Original Vintage designed t-shirts at http://www.vintagedge.com
Reply With Quote
  #10 (permalink)  
Old 07-31-2007, 12:58 PM
WebProWorld Pro
 

Join Date: May 2007
Location: DataCenter
Posts: 174
hostBrain RepRank 1
Default Re: 301 redirect code not working

Quote:
Originally Posted by vintagedge View Post
Thanks. Can you tell me how to do that? My service provider is unsure.
Unsure? wow.. (no comment)

Okay, here:

Quote:
1. Find the httpd.conf file of Apache

2. Inside the httpd.conf file uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (by removing the '#' sign)

3. Find the line ClearModuleList is uncommented then find and make sure that the line AddModule mod_rewrite.c is not commented out.
__________________
----Don't Call Me Brian----
Reply With Quote
  #11 (permalink)  
Old 07-31-2007, 02:19 PM
WebProWorld Member
 

Join Date: Sep 2003
Posts: 55
vintagedge RepRank 0
Default Re: 301 redirect code not working

Thanks. I will let them know.
__________________
Original Vintage designed t-shirts at http://www.vintagedge.com
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , ,



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

vB 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
how do I 301 redirect? Cloggie192 Google Discussion Forum 7 07-12-2007 11:06 AM
Is a 301 redirect the best way? raj7 Search Engine Optimization Forum 5 05-05-2007 03:05 AM
301 Redirect gbb011 Search Engine Optimization Forum 11 04-27-2007 01:08 AM
301 redirect jasonashby Search Engine Optimization Forum 11 04-17-2006 05:23 PM
301 redirect schmeetz Web Programming Discussion Forum 11 08-10-2005 01:54 PM


Search Engine Optimization by vBSEO 3.2.0