Title: 301 htaccess
Last modified: August 19, 2016

---

# 301 htaccess

 *  [kronossaturn](https://wordpress.org/support/users/kronossaturn/)
 * (@kronossaturn)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/301-htaccess/)
 * 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)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [16 years, 9 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178655)
 * Try this:
 *     ```
       #FORCE www
       RewriteEngine on
       RewriteCond %{HTTP_HOST} ^domain.tld [NC]
       RewriteRule ^(.*)$ http://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 🙂
 *  [Chuck Reynolds](https://wordpress.org/support/users/chuckreynolds/)
 * (@chuckreynolds)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178721)
 * The htaccess code I use for all my/client sites:
 *     ```
       # canonical redirect to no www
       RewriteEngine On
       RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
       RewriteRule ^(.*)$ http://%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.
 *  [Overflow](https://wordpress.org/support/users/acrane/)
 * (@acrane)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178723)
 * 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)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [16 years, 8 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178728)
 * Why not make a static front page? [http://codex.wordpress.org/Creating_a_Static_Front_Page](http://codex.wordpress.org/Creating_a_Static_Front_Page)
 *  [Chad](https://wordpress.org/support/users/lynneandchad/)
 * (@lynneandchad)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178730)
 * 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:
    [http://helpdesk.bluehost.com/index.php/kb/article/000498](http://helpdesk.bluehost.com/index.php/kb/article/000498)
   [http://helpdesk.bluehost.com/index.php/kb/article/000134](http://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!! 🙂
 *  [WatchCount.com](https://wordpress.org/support/users/watchcountcom/)
 * (@watchcountcom)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178770)
 * 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 [http://www.addon.com](http://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
   ^(.*)$ [http://www.addondomain.com/$1](http://www.addondomain.com/$1) [R=301,
   L]
 * It means “if the hostname doesn’t start with [http://www.addondomain.com](http://www.addondomain.com)
   then replace the whole thing with [http://www.addondomain.com/everything-else&#8230](http://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](https://wordpress.org/support/users/lynneandchad/)
 * (@lynneandchad)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178775)
 * 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.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 6 participants
 * Last reply from: [Chad](https://wordpress.org/support/users/lynneandchad/)
 * Last activity: [16 years, 5 months ago](https://wordpress.org/support/topic/301-htaccess/#post-1178775)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
