Forum Moderators: open

Message Too Old, No Replies

mod_rewrite and httpd.conf

how do they fit together?

         

NickH

3:42 am on Jan 29, 2003 (gmt 0)

10+ Year Member



Hi,

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

wilderness

4:26 am on Jan 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nick,
Welcome to Webmaster World.
There are others more knowlegable about this aspects than myself. I give you a brief answer and hope some others add quality :)

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.

jdMorgan

5:10 am on Jan 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nick,

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

andreasfriedrich

7:46 am on Jan 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a page about Apache´s Configuration Files [httpd.apache.org] available at the Apache website.

Andreas

NickH

1:08 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



Thanks everyone. Jim, I'll try that test at a low traffic time.

Nick