LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-17-2006, 05:57 PM   #1
geoman
LQ Newbie
 
Registered: Jan 2006
Posts: 3

Rep: Reputation: 0
cannot get 301 redirect to function


Hello all. My site is hosted on a Linux server running Apache. I am trying to use a 301 redirect in my .htacess file to go from non www to the www version of my domain. I have this in my .htaccess file...

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

Of course DOT is swapped in to get this message to post.

Unfortunately it doesn't work. My host said mod_rewrite is on. How can I tell if the .htaccess file is being run? Are there any other files that I need to modify to get .htacess to run the 301 redirect? The host is running Apache.

Any tips will be appreciated.

Last edited by geoman; 01-17-2006 at 06:00 PM.
 
Old 01-17-2006, 06:14 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Quote:
in my .htacess file to do from non www to the www version of my domain
I don't understand this. Are you saying you want:
http://yoursite.com/
to redirect to:
http://www.yoursite.com/
?

Because every browser I have tried serves the same page in this situation anyway...
 
Old 01-17-2006, 06:28 PM   #3
geoman
LQ Newbie
 
Registered: Jan 2006
Posts: 3

Original Poster
Rep: Reputation: 0
I don't understand this. Are you saying you want:
yoursiteDOTcom
to redirect to:
wwwDOTyoursiteDOTcom



That is exactly what I want to do. The reason is google, not users. When google spiders encounter a link without the www and it visits the page, GG often considered a different page. Inbound links are not credited and sometimes GG duplicate content penalties come into play.

Last edited by geoman; 01-17-2006 at 08:27 PM.
 
Old 01-17-2006, 06:44 PM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
I see. I am no guru at mod_rewrite, but you can check if the .htaccess file and mod_rewrite itself is working by putting this:
Code:
RedirectMatch permanent (.*)search.html$ http://www.google.com
in an .htaccess file. Now if you do a http://yoursite.com/search.html you should be redirected to google.

You get the idea here is to just simplify the rules for now to make sure that it is working, then you can go to work on your regex...
 
Old 01-17-2006, 08:23 PM   #5
geoman
LQ Newbie
 
Registered: Jan 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks a million bulliver. I put that into my .htaccess and used it to figure out where I could locate the file so that it would run. It also showed mod-rewrite was going and allowoverride was not set to none. Then I edited the file to do the 301 redirect and it worked. I appreciate your help.

In case you are curious, here is the reason for this....

aplawrenceDOTcom/Unixart/googlepagerank301DOThtml

I am new here so I had to swap DOT for .

Last edited by geoman; 01-17-2006 at 08:25 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding a redirect function in php mrobertson Programming 2 06-22-2005 08:40 AM
New kernel - VFS: Cannot open root device "301" or unknown block(3,1) j0y Debian 2 04-30-2005 09:14 PM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM
Wireless: Netgear MA 301 and MA401 Wientanz Linux - Wireless Networking 0 04-23-2003 02:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration