• I am trying to redirect all non www incoming posts to www via .htaccess. After installing my blog I used the non www setting for about a month but changed that now and want all incoming links to be redirected.

    I′m half way there and have put this .htaccess in my blog folder
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^cheap-webhosting.in$
    RewriteCond %{REQUEST_URI} ^/blog/$
    RewriteRule ^(.*)$ xxhttps://www.cheap-webhosting.in/blog/ [R=301,L]

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>

    # END WordPress

    However, the urls of the specific posts are still not redirecting:
    e.g.
    https://cheap-webhosting.in/blog/a-transfer-from-one-web-host-to-another/

    Doesn′t the second line in my .htaccess mean: Redirect everything in the blog directory and everything thereafter to the www version

    How can I implement this or have I already done this and what are the possible causes why this isn′t working?

Viewing 2 replies - 1 through 2 (of 2 total)
  • This should help:
    https://www.evolt.org/ultimate_htaccess_examples
    Scroll about 1/4 way down and it shows how to do seo friendly redirects.

    Thread Starter hostwolf

    (@hostwolf)

    Thanks samboll.

    This looks like the best one to use to care of all eventualities without hard coding:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/robots\\.txt$ [NC]
    RewriteCond %{HTTP_HOST} !^www\\.[a-z-]+\\.[a-z]{2,6} [NC]
    RewriteCond %{HTTP_HOST} ([a-z-]+\\.[a-z]{2,6})$ [NC]
    RewriteRule ^/(.*)$ https://%1/$1 [R=301,L]

    I′m just wondering why is it {2,6} and not {1,9} ? Isn′t that statement supposed to take care of all numerals or am I missing something?

    And what does the request for robots.txt do? Or what′s the purpose?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘.htaccess redirection’ is closed to new replies.