Forum Moderators: phranque

Message Too Old, No Replies

What am I doing wrong?

         

SonicDark

12:11 am on Nov 21, 2006 (gmt 0)

10+ Year Member



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

Is there something that I'm putting in incorrectly to do a 301 redirect from non www to www? For some reason I put this in and nothing occurs when I pop the .htaccess file on my server. It's running Apache.

Also, I have more sites that utilize subdomains. What do I need to do in the .htaccess file for sub domains to resolve the non www/www thing other than add sub\.domain\.com differently than a regular main domain?

[edited by: jatar_k at 12:24 am (utc) on Nov. 21, 2006]
[edit reason] changed to example.com [/edit]

jdMorgan

1:37 am on Nov 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is all you should need:

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

If it doesn't work, take a look at your server error file and see if it is trying to tell you anything.

Get this working first, and then we can discuss subdomains with working code as a basis.

Jim

SonicDark

4:53 pm on Nov 21, 2006 (gmt 0)

10+ Year Member



Thank you for your reply. Our IT guy is not really an IT guy so if we need something we are pretty much on our own. I created what you gave me in an .htaccess file but it doesn't resolve the non www/www. There is a server.c file, but other than that I don't see any other non HTML files beyond public_html shortcut. Thank you for your help

jdMorgan

4:58 pm on Nov 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put the .htaccess file into the same directory as your "home page" and robots.txt file -- in the "Web root" directory.

Jim

SonicDark

5:15 pm on Nov 21, 2006 (gmt 0)

10+ Year Member



Hi JD,

I've done that and its worked fine with my personal websites, but I'm trying to resolve the issues here at work. We have a few domains and different machines. The one I'm looking at resolving is <snip>. It is running Apache and I have FTP access to the root public_html folder that I'm dropping it into. When I drop it in nothing occurs or changes. Is there some other configuration preventing the .htaccess file from actually doing what is stated in the file? Thanks!

Jeff

[edited by: jdMorgan at 6:17 pm (utc) on Nov. 21, 2006]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

6:20 pm on Nov 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See the thread Beginning mod rewrite [webmasterworld.com] in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Also, checking your server error log will sometimes be quite useful in these cases.

Jim