Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 .htaccess redirects with WordPress



8:00 pm on Feb 19, 2011 (gmt 0)

Hello all!
First post but a long time lurker. Much respect goes out to jdMorgan as I have used their information more times then I can count.

Anyway, I am in the process of converting my static HTML pages over to WordPress. Everything was fine until I started deleting the old pages off of the web server and the URL's, instead of redirecting them out of my .htaccess files, are throwing a 404.

My WP is installed in /wp/ directory.
My redirect URL .htaccess is in root
The redirects work as long as the old .htm file is still located on the server. If it was deleted, WP returns a 404.
I am attempting to avoid adding a plugin that redirects pages as I would have to add in 3000 or so URL's in the plugin when I already have redirects in place...

I am using the following code in /wp/ directory:

# BEGIN WordPress
RewriteEngine on
# Unless you have set a different RewriteBase preceding this
# point, you may delete or comment-out the following
# RewriteBase directive:
RewriteBase /
# if request is for image, css, or js file
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|css|js|ico|png)$ [NC,OR]
# or if URL deals with my old static pages
RewriteCond %{REQUEST_FILENAME} \.(htm|html)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L]
# END wordpress

I have my standard redirects located in root.

This code is as recommended in another thread. I then added a "ignore .htm and .html" files in an attempt to fix this but it is not ignoring them as I hoped.

I tried putting the rewrite rules in the /wp/.htaccess file instead of root and that did not work.

Am I just chasing my tail? Thanks in advance for any direction you can offer me.


8:31 pm on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

The problem is likely the order of your rules.

You need the redirects to be listed before the wordpress rewrite code in the htaccess file - otherwise the rewrite code will kick in first once the files are deleted.


8:37 pm on Feb 19, 2011 (gmt 0)

Such a simple explanation and I thank you very much. I will try it now!


9:06 pm on Feb 19, 2011 (gmt 0)

Changing the order did not work. Files that exist are being rewritten properly, but files that are not on the server are still 404ing even though the rewrite rule is in place before the WordPress blurb. I tried putting the WordPress code at the bottom in root as well as putting the URL rewrite above WordPress code in /wp/.
Any other ideas?


9:22 pm on Feb 19, 2011 (gmt 0)

Oh my!
After posting the above, I discovered an extra WordPress rewrite block that was injected into the middle of my .htaccess file in my root. After searching for "WordPress" and found the offending code (around line 2000 of 4900), and putting the proper code at the bottom, all works well!
I wish to thank you for all that you do! Your guidence is appreciated more then I can type!
Take care!


9:34 pm on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

There may be further problems for any request where an internal rewrite is invoked from the root .htaccess file before an external redirect is invoked from the /wp/ folder .htaccess file.

Be careful about this. It can silently kill your site indexing and rankings with very few clues.


9:40 pm on Feb 19, 2011 (gmt 0)

I deleted the WordPress code block in the /wp/ .htaccess file and seems to be working.
However, after I add more redirect URL's, I will have to move the WordPress block in root back to the bottom of the file. So far, that is the only problem that I can come up with by just removing the /wp/ code block.


2:02 am on Feb 20, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

The major problem comes about if any particular URL request triggers an internal rewrite from within the root .htaccess file and then triggers an external redirect from within the .htaccess file in any sub-folder.

Due to the processing order within Apache mod_Rewrite, the rules will be invoked in the "wrong" order and internal server filepaths will be exposed back out on to the web within the redirect.


10:56 am on Feb 22, 2011 (gmt 0)

Thanks for this post.From many days i search that how can i create a redirect in word-press platform.So bro thanks for telling in this thread about Word press redirect.I bookmarked it.

Featured Threads

Hot Threads This Week

Hot Threads This Month