Title: .htaccess Rewrite Engine
Last modified: August 18, 2016

---

# .htaccess Rewrite Engine

 *  Resolved [pluto198](https://wordpress.org/support/users/pluto198/)
 * (@pluto198)
 * [19 years, 7 months ago](https://wordpress.org/support/topic/htaccess-rewrite-engine/)
 * Prior to installing WordPress, I had my .htaccess file set to redirect [http://www.macbasement.com/*](http://www.macbasement.com/*)
   to [http://macbasement.com/*](http://macbasement.com/*) (basically removes the‘
   www’ prefix, because I find it unnecessary) I had this working with the following
   code in my .htaccess:
    `RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST}
   ^www.macbasement.com$ RewriteRule (.*) http://macbasement.com/$1 [R=Permanent](
   Courtesy of John Gruber)
 * When WordPress was installed, it modified my .htaccess file, adding the following
   code after my code:
    `# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine
   On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}!-
   d RewriteRule . /index.php [L] </IfModule> # END WordPress
 * Now, “www.macbasement.com” returns a “page not found” error in my browser, while“
   macbasement.com” (sans ‘www’) works fine (WordPress permalinks and all)
 * I’m guessing there’s a certain way to combine two Rewrite rules, which I am not
   familiar with. Because separately, both codes work fine, but when combined they
   don’t work right together.
 * Could someone take the above two htaccess codes and combine them so they will
   work properly?
 * Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 7 months ago](https://wordpress.org/support/topic/htaccess-rewrite-engine/#post-481737)
 * Change your own rules to this:
    `RewriteEngine on RewriteBase / RewriteCond %{
   HTTP_HOST} ^www.macbasement.com$ RewriteRule (.*) http://macbasement.com/$1 [
   R=301,L]
 * The 301 is the same as “Permanent” (but more sensible since it actually tells
   you what the code being sent back is), and the L forces it to stop processing
   rewrites at that point and redirect the user immediately to the non-www URL.
 *  Thread Starter [pluto198](https://wordpress.org/support/users/pluto198/)
 * (@pluto198)
 * [19 years, 7 months ago](https://wordpress.org/support/topic/htaccess-rewrite-engine/#post-481749)
 * Perfect! Thank you!
 *  [vkaryl](https://wordpress.org/support/users/vkaryl/)
 * (@vkaryl)
 * [19 years, 7 months ago](https://wordpress.org/support/topic/htaccess-rewrite-engine/#post-481767)
 * Yes, it is! Thanks, Otto, something I didn’t know I needed has now been magically
   provided….
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 7 months ago](https://wordpress.org/support/topic/htaccess-rewrite-engine/#post-481834)
 * BTW, while the above *works*, the better way is as follows:
 * `RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule
   ^(.*)$ http://example.com/$1 [R=301,L]
 * Differences:
    – The dots in the domain name are escaped, thus making them actually
   match dots and not any single character. – The [NC] makes it case-insensitive.–
   The ^ and $ enclosing the rule make it a bit more intelligently match the entire
   URL when doing the rewrite.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘.htaccess Rewrite Engine’ is closed to new replies.

## Tags

 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [19 years, 7 months ago](https://wordpress.org/support/topic/htaccess-rewrite-engine/#post-481834)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
