Using .htaccess files to make your web site or blog to redirect/cloak affiliate links or improve SEO is a great idea. Unfortunately Wordpress rewrites the file whenever you make a change to the blog layout or permalink structure.

Does that mean you can’t use custom .htaccess commands with Wordpress? Of course not, but you do need to make the right modification to the initial .htaccess it creates.

Here’s an example to show you how simple it is. Just move the lines in bold from their position in the first sample to the position in the second:

SAMPLE 1:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^yoursite\.com [nc]
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]

RewriteRule ^dummyurl$ http://www.affiliateservice.com/afclick.php?o=6496 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>
# END WordPress

SAMPLE 2:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^yoursite\.com [nc]
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]

RewriteRule ^dummyurl$ http://www.affiliateservice.com/afclick.php?o=6496 [L]

# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

</IfModule>

NOTES:

1. If you already have a .htaccess file in place be sure to save it off the server before installing a new Wordpress blog. You will then need to integrate the original code into new .htaccess file if Wordpress botches things and overwrites the whole thing. It doesn’t always happen but is a good thing to keep in mind.

2. The extra .htaccess commands above show first, how to make all requests to your site start with www. for SEO purposes, and second, a simple .htaccess redirect. I will be explaining the redirect in detail in upcoming posts.

Blogged with the Flock Browser

Tags: , , , ,

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google



  Subscribe To Comments  


2 Responses to “Using Custom .htaccess File With Wordpress”

[...] @mfartr Using custom .htassess file with Wordpress [...]

Pamelia

October 28th, 2008 - 7:25 pm

Good post.

Leave a Reply