SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess and re-direct

    I have a website with re-direct. I also have Wordpress installed in directory /blog.

    The redirect is preventing Wordpress from working correctly.

    The redirect is in .htaccess and is like: Redirect 301 / http://www.domain.com/

    How can I correct this issue so the entire domain.com will redirect to http://www.domain.com/

    I have the url set to http://www.domain.com/ in general settings in Wordpress.

    Thanks for the help!
    Last edited by TechnoBear; Apr 16, 2012 at 12:28. Reason: Example URLs delinkified

  2. #2
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,421
    Mentioned
    273 Post(s)
    Tagged
    5 Thread(s)
    I don't know if I've understood your question properly. Are you trying to redirect from domain.com to www.domain.com, so that the www is always used? If so, this should work:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that does not work at all.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2006
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you need to move all your wordpress files into the root folder, then change the absolute path in the wp-config file

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    za,

    A Redirect like that would cause a loop IF located in the domain.com's DocumentRoot. TB's code is accurate, correct and the most efficient use of mod_rewrite. Your "it doesn't work" is a useless comment, though, as you did not give any indication of what's not working (if mod_rewrite is not enabled, you should get 500 errors; if it is, .htaccess should be the file examined by Apache - you are using Apache, aren't you? - and the code is picture perfect).

    As usual (with mod_rewrite questions), please specify EXACTLY what you're trying to do and provide us with the code you're using as the code often has some error which can be quickly spotted by the trained eye.

    Regards,

    DK

    Quote Originally Posted by zactive View Post
    I have a website with re-direct. I also have Wordpress installed in directory /blog.

    The redirect is preventing Wordpress from working correctly.

    The redirect is in .htaccess and is like: Redirect 301 / http://www.domain.com/

    How can I correct this issue so the entire domain.com will redirect to http://www.domain.com/

    I have the url set to http://www.domain.com/ in general settings in Wordpress.

    Thanks for the help!
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2011
    Location
    Utah
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TechnoBear View Post
    I don't know if I've understood your question properly. Are you trying to redirect from domain.com to www.domain.com, so that the www is always used? If so, this should work:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
    Sometimes your server can be picky on what it will do inside the .htaccess file. I would hit up your web hosting company about making changes, because this should work.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To say the code is not working is perfectly valid since it is not. I never said the code itself is written wrong as it is not because it is the first type of code I had tried first as it is in my coding toolbox. Though it creates issues. The server should be apache as that is what the host has told me.

    Bottom line I need all domains to be http://www.domain.com/

    I need the wordpress directory and root directory to work. Wordpress directory = /blog

    Not sure how I could better explain this.

    Thanks!
    Last edited by TechnoBear; Apr 16, 2012 at 23:15. Reason: Example URL delinkified

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    za,

    We're just not connecting. Use the following code in the DocumentRoot's .htaccess:
    Code:
    RewriteEngine on
    # force www but substitute your domain name
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
    
    # place WP's code here but WITHOUT the <IfModule> wrapper, without the RewriteCond %{REQUEST_URI} index.php but with the RewriteBase /blog
    RewriteBase /blog
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? index.php [L]
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That did it dklynn, thank you!

    Is there a way so it re-directs to http:// instead of just www. though?

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    z,

    Sure. Reverse the logic of the first block like
    Code:
    # force NON-www but substitute your domain name
    RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
    RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]
    Note: This will send everything (parked domains, in particular) to http://example.com.

    That, too, is in the tutorial (and sample code) linked in my signature so it was there for the taking if you'd only look around just a bit.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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