Htaccess to legacy directories under WordPress

I have a site which is now using WordPress as the front end.

I do however have other directories with around 600 files in them that I want people to access until I have the time to put them into WordPress. However, some are producing a “Not Found” error message from WordPress. A typical URL would be http://my.domain/articles/article.shtml (all URLs would have a .shtml or .html suffix.

It has been suggested to me to put a .htaccess file in each directory I want people to access with the lines…

Options +FollowSymLinks
RewriteEngine Off
RewriteBase /

Well, the second line was actually suggested. Will this override the .htaccess file in the root directory with the WP lines?..

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

# END WordPress

Alternatively, are there lines I can add to the root .htaccess?

Thanks,
Peter

Hi Peter!

Well, WP creates it in the DocumentRoot but adds the RewriteBase to give an additional redirection to ALL requests, therefore, in my mind, it confuses the issue with non-WP requests. Therefore, for me to keep matters clear in my mind, I WOULD move it to WP’s directory and eliminate its RewriteBase (and any leading / from its redirection).

Regards,

DK

I hear what you are saying, but I can’t get my head around the effect on “permalinks” such as http://www.peterwade.com/believing-and-risk . I suspect that since the URL is pointing to the document root and not the subdirectory, then it needs WP stuff in the root .htaccess. Any comment? And thanks.

Yes, Dave, I have WordPress in a separate directory, though index.php is still in the root directory. Because of this, I’ve left the WP .htaccess in as part of my root .htaccess (I have some redirections there and also some “deny from” statements out of my old CMS system.) Is there an advantage to moving the WP stuff into its own .htaccess in the subdirectory?

Thanks again,
Peter

Hi Peter!

THANK YOU for understanding my teaching style and not take what could have been perceived as personal attacks personally!

Hmmm, “outside the WordPress directory?” It sounds as though you were smart enough to keep WP in a subdirectory. Moving WP’s mod_rewrite out of the DocumentRoot to its subdirectory (my perception of the RewriteBase / statement you’d had) is also an excellent move!

Oh, well, so long as things are now working, I’ll assume it’s all fixed (and not try to fix what isn’t broken).

Please come back when you have other difficulties.

Regards,

DK

Hi pos!

Get ready for some rants as you’ve not looked at other posts and your code has many of the same errors I comment on routinely. :mad:

Okay, WP is greedy with its mod_rewrite code but there is NO EXCUSE for anyone to tell you to add an .htaccess file to every directory! .htaccess is hierarchical so having one in the DocumentRoot means that EVERY directory request will comply with the DocumentRoot’s .htaccess before the ones in the path then the directory the request is made. Shame on whomever it was that told you to add useless files! :mad:

Not Found? If the files exist, even WP’s mod_rewrite will leave them alone; that’s what the RewriteCond %{REQUEST_FILENAME} !-f tells mod_rewrite ("If the requested file does NOT {note the !} exist, then check the directory …

Another PET PEEVE of mine is seeing those who profess to be webmasters include <IfModule>…</IfModule> wrappers in .htaccess files. WHY would any webmaster do that? What it is directing Apache to do is check that mod_rewrite is enabled each and EVERY time a file request is made! How wasteful is that? To me, the professionalism of a webmaster is measured in large part by knowing what his/her code does. By allowing WP’s “noobie protection code” to remain in your .htaccess, you’ve shown that you’re in the “script kiddie” mode, i.e., not understanding the impact of the code you use. REMOVE THOSE WRAPPERS! They slow the server for you AND all those on the shared server with you! :kaioken:

RewriteBase is yet ANOTHER case in point! It’s used to UNDO a mod_alias redirection so mod_rewrite can work on it. WHERE IS YOUR Redirect (or Alias) directive? Not there? Then RewriteBase shouldn’t be there either! :mad:

As for your RewriteRule ^index\.php$ - [L] line, it’s completely absurd as it’s only conceivable function is to eliminate looping with the next RewriteRule - BUT that’s already prevented with the -f conditional statement! Repeating this repetitively is also wasteful! :mad:

Finally, using an absolute redirection in the second RewriteRule will cause Apache to look at the server’s ROOT directory (NOT your DocumentRoot) FIRST for index.php before it looks to your DocumentRoot. Lose the leading /!

Result:

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

Please note that I also added a ? to the remaining RewriteRule’s regex to account for the empty URI (http://example.com will fetch example.com’s DocumentRoot’s DirectoryIndex file but the request URI is just not there, is it?). Just covering all the bases!

Okay, now that you feel sufficiently “abused,” please know that this is NOT a personal attack but a learning session for you AND for other members! The problems addressed above are important (IMHO) for a webmaster to KNOW yet I see these same mistakes over and over and … In other words, you’re not the first and will not be the last to make the mistake of leaving WP’s code alone.

If you’ve lasted this long, you will have learned WHY and HOW you should have changed their code. Since my “job” is to help you learn, I will have succeeded! :Partier:

If you have any questions, please ask. Questions will help you understand and, if you have the question, someone else will likely benefit, too!

Regards,

DK

Too true! I guess you should leave it alone until we take a closer look at it with the .htaccess that’s working and knowledge of which subdirectory WP lives in.

Regards,

DK

Thanks, Dave. I did search extensively on the WordPress forum, and some on SitePoint. I’m convinced many forums use very poor search engines. I found one other guy on WordPress with the same problem I was having, but no answer to his query. I’m amazed that WordPress does not give more detail about .htaccess.

So I’m relieved for find someone who knows what he is talking about. I’ve made the changes you detailed and all appears to be working ok.

Not Found? If the files exist, even WP’s mod_rewrite will leave them alone; that’s what the RewriteCond %{REQUEST_FILENAME} !-f tells mod_rewrite ("If the requested file does NOT {note the !} exist, then check the directory …

Yes, the files WERE there outside the WordPress directory but it took over and sent a Not Found message. I do not know why.

Okay, now that you feel sufficiently “abused,” please know that this is NOT a personal attack but a learning session for you AND for other members!

Thanks, Dave, for teaching a 77-year-old some more things! I didn’t take it personally. I’m just glad I’ve got it working.

Peter