301 redirect for subfolder question

by 5 replies
6
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.
#programming #301 #question #redirect #subfolder
  • 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
    • [ 1 ] Thanks
  • Thank you very much, Steve. That did work for me.

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

      Steve
      • [1] reply

Next Topics on Trending Feed