Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post

    .htaccess 301 redirect entire domain

    Hello all.

    I have been tasked with redirecting our entire domain with a 301 to make sure that "www" gets added to everything. However, whatever I try online (things I've come accross like blogs and articles on the topic) is not working - I keep getting a 500 error.

    Could someone please help me with the steps of adding "www" to "mydomain.com" in every instance? Such as:

    "mydomain.com/somepage.php/"
    "mydomain.com/images/image.jpg/"
    "mydomain.com/blogpost/"

    I'm so lost.
    Thanks very much!

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    can you set up another vhost on your server?
    if so, set up one for mydomain.com, second for www.mydomain.com and in root directory of domain.com place .htaccess with this:
    Code:
    Redirect 301 / http://www.mydomain.com
    ---edit---

    without second vhost:
    in .htaccess:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mydomain\.com$ [nc]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
    Last edited by patryk; 10-29-2012 at 08:10 PM.

  • Users who have thanked patryk for this post:

    ajhauser (10-29-2012)

  • #3
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    Awesome, I will try this now - thank you. I know that for one thing I did not have the "RewriteEngine on" bit.

    And yes, unfortunately I don't have access to the host at this time.

    I'll check it out though - THANK YOU VERY MUCH!

  • #4
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    Ok this works great!
    Thank you!

    My only other question is how I would apply it to other sections of the site. For example, everything in my root folder gets the "www" added, but when I head over to the blog, it is without "www".

    http://hauserdesigngroup.com/wordpress/

    Do I need to add another .htaccess file or - ?

  • #5
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    ... which may be because I have the following .htaccess file already in that directory:

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>

  • #6
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    oh sorry man. that's my mistake
    try this instead:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mydomain\.com [nc]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
    (just remove that '$' from condition)

  • Users who have thanked patryk for this post:

    ajhauser (10-29-2012)

  • #7
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    Awesome - I'll try that now.

    What does the $ in the condition do?

  • #8
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    in posix regular expresions '^' means begining of line and '$' means end of line

  • #9
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    AH, ok I see - thank you.
    Unfortunately when I go to http://hauserdesigngroup.com/wordpress/ it still doesn't add the "www"...

    And as you can tell, I'm completely useless in this arena.
    Thoughts?

  • #10
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    you might have some conflicting rewrites in wordpress directory
    all other directories are being redirected correctly?

    u know that .htaccess can be overridden with other .htaccess placed in subdirectories right?
    Last edited by patryk; 10-29-2012 at 10:41 PM.

  • #11
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    I think you're right - I think that's the problem. I have this in the subdirectory .htaccess file - can we somehow combine the two?

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>

  • #12
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    try changing rewriteBase to 'RewriteBase http://www.domain.com/wordpress/'
    ...i'm not sure if that will do the trick tho (and probably wont)
    ------------------
    disregard this - it's totaly wrong
    Last edited by patryk; 10-29-2012 at 11:44 PM.

  • #13
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    idk wordpress so i can't tell you how it's done, but check this out:
    if u click http://hauserdesigngroup.com/wordpress/?p=1032
    you'll get 301 redirection to http://hauserdesigngroup.com/wordpre...in-10-seconds/
    i'm guessing it's some config variable in wordpress. try adding www prefix there (just guessing at this point).
    in fact your wordpress site is stripping www. prefix if you try to use it.
    also check this: http://wordpress.org/support/topic/m...d-to-multisite
    Last edited by patryk; 10-29-2012 at 11:42 PM.

  • Users who have thanked patryk for this post:

    ajhauser (10-29-2012)

  • #14
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    Good deal - I'll start a thread in the Wordpress forums - thanks very much for all your help, I really appreciate it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •