|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Payments Humor Music |
How to use Apache .htaccess and mod_rewrite without corrupting the FrontPage ExtensionsPeople who publish their websites with Microsoft FrontPage to an Apache server often discover that if they modify their site's .htaccess file manually or if they use certain cPanel features that modify .htaccess, it corrupts their FrontPage Extensions, makes the site display improperly, and can make it impossible to publish the site with FrontPage. The fix is usually to uninstall, clean up, and reinstall the FrontPage Extensions, which has the undesirable side effect of emptying all the site's FrontPage-specific folders that start with an _underscore (including any _underscored folders that are inside other folders that don't start with an underscore). In a worst case, it's necessary, or at least easiest, to republish the entire site. After this has happened a couple of times, many people decide that they can't use .htaccess if they publish with FrontPage. But it is possible.
I did some experiments to answer these questions: Is there a security feature of FrontPage Extensions that checks whether .htaccess has been edited and freezes the site if it has?That is, do the FrontPage Extensions use any tampering detection methods on .htaccess such as checksum verification, timestamp checking, or a hidden or encrypted shadow file that must always match? The answer to all is No. I was able to do all of the following without corrupting the FrontPage Extensions:
It is only the settings specified in .htaccess that corrupt the FrontPage Extensions. It is not the act of tampering with the file. Can you modify your server's configuration so you can use the FrontPage Extensions and still have full use of .htaccess, including mod_rewrite?Yes. Here's how: Navigate to each of the following three files (using, for example, cPanel > File Manager) and edit each one using the Edit File command. If you decide not to save the file, just close the browser window. The file is not saved unless you click the Save button.
At the top of each file you will probably find the following line. If it's not there, see Note 1 at the bottom of this page: Options None It was put there when the FrontPage Extensions were installed. Don't delete or modify that line. It gives this folder a secure starting point by turning OFF any insecure options that might be enabled in folders above it. It is most likely this line that prevents publishing successfully with FrontPage, but removing it might weaken the folder's security. Instead, make a specific modification that has fewer side effects: At the very bottom of each file, add the following on its own line: Options +SymLinksIfOwnerMatch Save the file. Do the same for each of the three files. You do not have to make any modifications to the top-level /public_html/.htaccess file. If you ever have to uninstall and reinstall your FrontPage Extensions, you must reapply the mods to those three files afterwards because reinstalling the FPE resets all .htaccess files in the site to the FrontPage default ones, discarding any modifications you have made. Fortunately, it does save a backup copy of each old .htaccess file, in the same folder where it was, with a name that has 10 digits appended, like this: .htaccess.0123456789 You can use the contents of each backup file to restore the corresponding .htaccess file to what it was before you reinstalled the FPE. After doing that, the backup files with the appended digits have no function and can be deleted. Alternate methodThere is another .htaccess line that will achieve the same purpose as the one above: Options +FollowSymLinks When first writing this article, I thought the Apache documentation seemed to imply this was less secure. However, the newer documentation appears to imply that neither is more secure than the other, so the two methods are probably equivalent, and they both worked for me. Without fully understanding the differences between the two, what I'd suggest is that if one doesn't work, try the other. Test resultsI've tested the configuration described above with the following cPanel features, and they all work without corrupting the FrontPage Extensions. By the end of testing, they were all enabled simultaneously:
But cPanel can't be fully trusted to manage .htaccessIn the course of testing, it became evident that there are some flaws in how cPanel manages the .htaccess file. cPanel is not part of Linux or Apache. It is an independent module that provides a user friendly interface to some of Apache's features. It takes options you select and translates them to .htaccess code. But like almost any automated code generator, its features are somewhat crude and error-prone compared to what you can accomplish if you work with the underlying system directly. In order to work properly, cPanel has to correctly interpret the existing contents of .htaccess, which it seems unable to do in some circumstances. Then, if its method of modifying .htaccess consists of inserting a block of cookie-cutter code without regard for possible conflicts, it's no wonder .htaccess can end up in disarray. Unless you have no other choice, cPanel should not be completely trusted with management of your .htaccess files, whether you use FrontPage or not. It is much more advisable to determine the correct code to achieve a desired objective, and insert it into .htaccess manually. You can still use cPanel to generate the code, but you should look at what it did and decide whether it's correct. A good method for making changes, if you must use cPanel, is to:
Examples of how cPanel inserted code. Some had errors.Index Manager Turning off indexes for the public_html folder inserted this code into .htaccess: Options All -Indexes This is more meddlesome than is required. The "All" enables features you might not want or need. This would turn off indexing, without the side effects: Options -Indexes MIME Types I set up a MIME type for Windows wma files. cPanel inserted this code. No problems: AddType audio/x-ms-wma wma Enabling the default Hotlink Protection caused cPanel to insert the following code, which has a real error in it. RewriteEngine on The last line above should have an L in it [R,NC,L]. As long as this is the only block of Rewrite code in your site (which is what cPanel expects), it won't cause problems, but if you have other Rewrite blocks, it will cause problems. This is because cPanel appears to reserve the RewriteEngine for Hotlink Protection only. Considering how often mod_rewrite is needed for other purposes, this is wasteful on the part of cPanel, and it leads to the following errors:
In other words, cPanel is unable to distinguish between mod_rewrite lines that relate to Hotlink Protection and ones that are there for other purposes. This can make a mess of your .htaccess file. Conclusion: do not use cPanel Hotlink Protection. Do it yourself manually. Redirects This code was inserted: RedirectMatch temp ^/dummy2.htm$ http://mydomain.com/dummy1.htm Note how the redirect avoids using the RewriteEngine. This is evidence that RewriteEngine is reserved for the use of Hotlink Protection only. But the redirect does work. IP Deny I set it to deny my own IP address. It changed this (default created by the FrontPage Extensions): <Limit GET POST> To this: <Limit GET POST> This part allows showing the Forbidden page, even to the denied party: <Files 403.shtml> This line does the denial. deny from ###.###.193.45 Removing the IP Deny using cPanel did not restore the modified .htaccess sections to their previous default state, but it makes no difference. The default FrontPage "order deny,allow" lines allow anyone to GET or POST, and no one to PUT or DELETE. The changes that DenyIP made don't change that, but it has to change the order in which it's done so it can apply the deny line globally. A concise reference on how to interpret the Order, Allow, and Deny directives is at http://httpd.apache.org/docs/1.3/mod/mod_access.html. If two or more rules conflict in a way that can't be resolved any other way, whichever rule Apache processes last (the one farthest down in the .htaccess file) overrides earlier conflicting ones. [Related article: denying IP addresses in .htaccess using wildcard and CIDR notation.] Notes:
As an example of something you can do with manual .htaccess editing, that cPanel cannot do correctly, these two sections that both use the Rewrite Engine happily co-exist. The first block redirects www to non-www. The second prohibits hotlinking: RewriteEngine On RewriteCond %{HTTP_REFERER} !^$ Questions are welcome in the discussion forum. |
|
|
|
|
|
Copyright ©2012 Steven Whitney. Last modified Thu 11/08/2012 23:43:09 -0800. |
||