301 redirect for subfolder question

5 replies
I'm able to redirect for the main page using this code:


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

However, the same conditions don't apply for a subfolder as I can't get http://domain.com/blog to redirect to http://www.domain.com/blog.

Anyone know how to redirect for this subfolder?

Thank You.
#301 #question #redirect #subfolder
  • Profile picture of the author Steve Diamond
    Change your code to this:
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    That should do it. This version tells it to make sure it matches all the way to the end of the URL. Your original didn't.

    Steve
    Signature
    Mindfulness training & coaching online
    Reduce stress | Stay focused | Keep positive and balanced
    {{ DiscussionBoard.errors[1014058].message }}
  • Profile picture of the author millionairemoney
    Thank you very much, Steve. That did work for me.

    Do you know the code for a regular URL redirect on WP?
    {{ DiscussionBoard.errors[1014101].message }}
    • Profile picture of the author Steve Diamond
      Originally Posted by legitimatefreestuff View Post

      Do you know the code for a regular URL redirect on WP?
      I'm not sure what you mean by this. Please explain and give an example.

      Steve
      Signature
      Mindfulness training & coaching online
      Reduce stress | Stay focused | Keep positive and balanced
      {{ DiscussionBoard.errors[1014674].message }}
      • Profile picture of the author millionairemoney
        Originally Posted by Steve Diamond View Post

        I'm not sure what you mean by this. Please explain and give an example.

        Steve
        Just the same as I mentioned in my first post but for WP

        Example:

        redirecting http:// wordpressblog.com to http:// www.wordpressblog .com.

        Inserting a .htaccess doesn't do the trick in a WP blog for me.
        {{ DiscussionBoard.errors[1022920].message }}
        • Profile picture of the author Steve Diamond
          This should be a complete solution for WordPress. Just make sure that this code comes before the WP-generated code in your .htaccess file.

          Code:
          Options +FollowSymLinks
          RewriteEngine On
          RewriteBase /
          RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
          RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
          Steve
          Signature
          Mindfulness training & coaching online
          Reduce stress | Stay focused | Keep positive and balanced
          {{ DiscussionBoard.errors[1023582].message }}

Trending Topics