Jump to content

Apache content negotiation


midnite
 Share

Recommended Posts

Apache content negotiation works only in /var/www/localhost/htdocs and only for index.html.var???(i am meaning that turn Multiviews off, and use _solely_ content negotiation)i have tested index.html.var does not work outside.And even DirectoryIndex index.php.var does not work in /var/www/localhost/htdocs neither :)(It is very troublesome with so many restrictions, and only a static page!!)Is there a way to fix those?Or is it my fault for the mis-configuration? (i hope it is)Or the worst case, it is a limitation of Apache :) :)

Link to comment
Share on other sites

Errrr... You're not really saying what you configuration is here. Do you mean to say you've practically followed all examples "as is" and are on Linux?Well, if so, know that of course content negotiation works in all directories. Just denote negotiation directives with the <Directory> directive. You could also use another suffix other then "var" with which you'll denote with the directive

AddHandler type-map .var

where ".var" is the actual extension you'll refer to as a type map variable, rather then a file name. Your actual files must be named in accordance with the variable's meaning, such as index.html.en and index.html.de.Read more about Apache's content negotiation mechanism or better yet, if you can, install the PECL HTTP extension. It contains the http_negotiate_*() functions, which do negotiation within the PHP file itself. Instead of leaving the negotiation to Apache, you'll leave it to PHP. That's how I personally prefer to do it. It's easier and more portable too (since you're only depending on PHP, not on Apache/IIS/whatever).

Link to comment
Share on other sites

alright, thanks so much for your reply, boen_robot.Here's some main lines of my configuration files:/etc/apache2/modules.d/00_default_settings.conf

<IfModule dir_module>	   DirectoryIndex index.html index.html.var</IfModule>

/etc/apache2/modules.d/00_mod_mime.conf

DefaultType text/plain<IfModule mime_module>TypesConfig /etc/mime.typesAddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddHandler type-map var</IfModule><IfModule mime_magic_module>MIMEMagicFile /etc/apache2/magic</IfModule>

/etc/apache2/modules.d/00_languages.conf

AddLanguage en-GB .en-gbAddLanguage en .enAddLanguage en-US .en-USAddLanguage zh-HK .zh-hkAddLanguage zh .zhAddLanguage zh-TW .zh-twAddLanguage zh-CN .zh-cnAddLanguage ja .jaLanguagePriority en zh ja

/etc/apache2/vhosts.d/default_vhost.include

DocumentRoot "/var/www/localhost/htdocs"<Directory "/var/www/localhost/htdocs">		Options FollowSymLinks		AllowOverride None		Order allow,deny		Allow from all</Directory>

now, with these settings, the server can give index.html.en or index.html.zh according to browser's setting.(Please note that Options FollowSymLinks, but not Options FollowSymLinks Multiviews)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++But, unfortunately, if i change to:/etc/apache2/modules.d/00_default_settings.conf

<IfModule dir_module>	   DirectoryIndex index.php index.php.var</IfModule>

and if i only have index.php.* but no index.php, it returns 403 Forbidden. (because no Options Indexes)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++even if i change back to index.html and change the path to other places, as follows:/etc/apache2/modules.d/00_default_settings.conf

<IfModule dir_module>	   DirectoryIndex index.html index.html.var</IfModule>

/etc/apache2/vhosts.d/default_vhost.include

DocumentRoot "/myweb"<Directory "/myweb">		Options FollowSymLinks		AllowOverride None		Order allow,deny		Allow from all</Directory>

of course i have index.html.en and index.html.zh in the folder /myweb, but again, no index.html.It gives me 403 Forbidden too.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Thanks so much. You may try it on your own server.I would like to stick with Apache as i dont want to increase PHP overhead.And this purely content negotiation (without Options Multiviews) is faster, as stated in the documentation.

Link to comment
Share on other sites

Are you sure it's faster with Apache then with PHP? As it says in where in which documentation? Any solid tests to prove this? I haven't made any, so I'm opened to any test suite there is out there.Its just that I've tried negotiation before myself and never really made it work. If I try it today, I may succeed, but since I usually do more then negotiating a single resource, I won't revert back to this technique.Negotiation with PHP gives you far better degree of control then Apache will ever give you. Besides negotiating, you can on the fly choose one (or more!) resources based on the negotiation results, send a custom HTTP status code (which would deal with custom error pages), and a lot more. Even if there's a small performance penalty, it's just as worth it, as keeping a CSS file separate is worth the extra HTTP connection.The only thing I use Apache for today is URL rewriting. To rewrite example.com/%%SomeURI%% to example.com/index.php?uri=%%SomeURI%%, and let PHP deal with the rest.

Link to comment
Share on other sites

For the problem i mentioned, i have somehow solved it by adding Option MultiViews. I did download the source code and wish to dig into it. But i think i wont have time to do so recently.i think there was a minor misunderstanding between us. i meant using Option MultiViews is a bit slower than not using it, said in the manual./etc/apache2/modules.d/00_default_settings.conf

# The index.html.var file (a type-map) is used to deliver content-# negotiated documents. The MultiViews Options can be used for the# same purpose, but it is much slower.

But anyway, dont bother. i used this powerful function now =)Why i do not want to make it PHP because if it works fine solely with Apache, better not the depend on another application. And also, i may disable PHP in some directories for security reasons.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++It's really good to hear that you use Apache mod_rewrite. I have a question about it, and being unsolved for months. But it seems that it goes fine now in this new version of apache. I will test it throughly later and ask for your comments if necessary =)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...