Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] [OT] Creating user-friendly URLS with mod_rewrite/Apache



> make sure you have
>  Options +AllowOverride
> for the directory where .htaccess is.
Am I correct that the "Options +AllowOverride" option goes into my
httpd.conf file?
yes



My current httpd.conf file has only this, which makes me unconfident
that it's the right file:

# This is here for backwards compatability reasons and to support
#  installing 3rd party modules directly via apxs2, rather than
#  through the /etc/apache2/mods-{available,enabled} mechanism.
#
#LoadModule mod_placeholder /usr/lib/apache2/modules/mod_placeholder.so
ServerName localhost

The apache.org file is a little hard to grasp when it comes to
determining the right syntax to use here.

The way how apache conf works varies from distribution. Main file
usually includes some other files to configure virtual hosts and
modules.

Assuming that you edit the proper file, you can place something like:

<Directory /path/to/dir>
 Options +AllowOverride
</Directory>

Is there a global way I can say to always obey the directives of a local
.htaccess file if it present in a directory?

<Directory /Path/To/DocumentRoot>
Options +AllowOverride
</Directory>

any subdirectory will respect .htaccess

"However, in general, use of .htaccess files should be avoided when
possible. Any configuration that you would consider putting in a
.htaccess file, can just as effectively be made in a <Directory> section
in your main server configuration file."

This is off by default for two reasons
- if you request /dir/a/b/c, then it apache would check directories
"dir", "dir/a", "dir/a/b" and "dir/a/b/c" for .htaccess. It performs
stat() and parse .htaccess every request which might slow down a bit
if you are doing 500-1000 requests per sec.
- whoever have access to subdirectories of "dir" will be able to put
his own .htaccess files. I'm not sure about this, but maybe they can
tell apache to follow sym links and symlink /etc. But if you have PHP,
noone would bother :)

If you have live production server, you can do the same thing if you put
contents of your .htaccess file into <Directory> or <Location> directive.

<VirtualHost example.com>
<Location />
  RewriteEngine On
  RewriteRule....
  ....
</Location>
</VirtualHost>

Hmm... well, I do have access to my Apache configuration files on both
my home environment and my hosting service.

Although, I think for portability reasons I should probably stick to
using an .htaccess file.

What do you guys think is better?

If you distribute code, .htaccess is easier. On many hosts who provide
webservice, mod_rewrite and override are on by default. So unless you
are building a High Availability server, keep it in .htaccess.

romans
http://grr.void.lv/cv


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links