• hi guys I need help regarding .htaccess, I’m confuse I have an existing .htaccess

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

    And I want to add this lines

    RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
    RewriteRule ^(.*)$ hEp://www.domain.tld/$1 [R=301,L]

    Now I don’t know where to add or remove some line here.

    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Try this:

    #FORCE www
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain.tld [NC]
    RewriteRule ^(.*)$ https://www.domain.tld/$1 [L,R=301]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /mysite2009/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /mysite2009/index.php [L]
    </IfModule>
    
    # END WordPress

    I have it in that order on my htaccess (to remove www, but same idea) and no issues ??

    The htaccess code I use for all my/client sites:

    # canonical redirect to no www
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
    # protect wpconfig at all cost
    <files wp-config.php>
    Order deny,allow
    deny from all
    </files>
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    That will 301 redirect to non-www version of the site (personal thing, i don’t like the extra chars). It will help protect your config file and add the typical wordpress mod_rewrite code…

    If you need it in that “mysite2009” directory then add that but my code assumes root.

    On the htaccess note. Is there any way to add an index.html to the site root where WP resides in which that is the default page then when the user clicks a link it goes to WP’s index.php.

    I’ve tried adding:

    DirectoryIndex filename.html

    but that messes up the site when i try clicking back to home. not to mention will not let me log into the admin section.

    thanks in advance.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Chad

    (@lynneandchad)

    I have a slightly different .htaccess problem…

    I’m setting up a second WP installation on an AddOn domain and trying to configure .htaccess to eliminate duplicate content issues. My goal is to prevent people (and search engines) from accessing the site from any of these options:

    addon.primary.com
    www.addon.primary.com
    primary.com/addon
    www.primary.com/addon

    I’ve been using the code found in these two articles:
    https://helpdesk.bluehost.com/index.php/kb/article/000498
    https://helpdesk.bluehost.com/index.php/kb/article/000134

    and have tried EVERYTHING I can think of with not luck! One is designed to prevent the subdirectory approach and the other the subdomain angle.

    I can intermittently get the redirects to work, but it always blocks me out of my login page.

    Any advice would be GREATLY appreciated!

    PS, I’ve also noticed that the code that forces the 404 (above) has a habit of breaking the theme of the blog… not sure why!!! help!! ??

    LynneAndChad:

    I would imagine that your WP installation would need to know nothing about primary.com and only have URLs and config options that reference addon.com or https://www.addon.com (decide www- or non-www first).

    Also, that second Bluehost support article (#134) seems to try to attack a few needs within 1 .htaccess file. It tries to tackle the “non-primary.com” issue you want to solve, but also integrates the “non-www” solution as well. And also it seems like that solution only address URLs of when the visitor is attempting to access your homepage only — but doesn’t handle other pages on your addon domain.

    I haven’t tested this, but maybe give it a whirl:

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

    It means “if the hostname doesn’t start with https://www.addondomain.com then replace the whole thing with https://www.addondomain.com/everything-else&#8230; (Addmittedly, however, I still haven’t grasped the full extent of the $1 parameter, but I think that’s how it works here.)

    Good luck,

    -WC

    Chad

    (@lynneandchad)

    Hey WatchCount

    Thanks for the advice… I’ll have to give it a shot. I wound up going in a different direction for the site I was setting up when I posted… but knowing me, another domain name can’t be too far in the future ??

    Thanks again!

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