Forum Moderators: open
I'm fairly new to web authoring. I'm looking at using mod_rewrite in .htaccess to restrict access by spambots. I think I understand the mod_rewrite directives I intend to use (thanks for the many examples on this forum), but I'm not quite sure where httpd.conf fits in. Is httpd.conf an alternative to .htaccess? Or is it a separate configuration file, in which I can specify that mod_rewrite is active?
Thanks,
Nick
httpd.conf is not availbale to every website. In fact I believe it is part of having your own server?
Even htaccess is not avaialbe for every website to access. It depends entirely on what your host offers.
Welcome to WebmasterWorld [webmasterworld.com]!
As wilderness says, most Webmasters don't have access to httpd.conf because it is the configuration file for Apache server. If you own or rent the entire physical machine, then you may have access to it. The basic idea is that httpd.conf can be used to make changes which affect all sites hosted on that machine, so it would be insecure if not unworkable or impossible for multiple people to share httpd.conf.
The alternative is to use .htaccess, a file which can exist in any directory of an account on an Apache server. While it is far less efficient to do many things in .htaccess compared to doing the same things in httpd.conf, it is still a workable solution for sites hosted on a shared server.
(Note that shared server does not imply shared IP address, since one comupter can have multiple network interface cards, each with a different IP address.)
mod_rewrite can be used in either context - httpd.conf or .htaccess - although the syntax of the rules changes slightly between these two environments. The examples given in the Apache mod_rewrite documentation make the differences clear.
An easy way to tell if you have mod_rewrite available to you is to create a rule like this in your top-level directory .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^sillyfile\.html$ /index.html [L]
Now request the page "sillyfile.html" from your domain. If mod_rewrite is working, your browser will be served the index.html file in place of sillyfile.html. The sillyfile.html page need not exist, but index.html must be there; If necessary, you can change the line above to use index.htm or any other file that is actually present.
The above test is quick and easy. It'll either work, or you'll get a server error. Be prepared to delete the modified .htaccess file quickly and restore from a backed-up copy of your original .htaccess if your site is live and has heavy traffic! (And do this test during a low-traffic time, too!) If it fails, check your raw error log and see what it says. If the module is not available, it will usually say so.
For an overview of mod_rewrite and links to more resources, try this Introduction to mod_rewrite [webmasterworld.com].
HTH,
Jim
Andreas