You are not logged in.
Hi,
I`m using a test environment with apache http server and php for web development.
I have serveral virtual hosts, each with its own config file as described here.
All website files are located in /srv/http in their own subdirectory.
In /etc/httpd/conf/httpd.conf I have following directory settings:
...
DocumentRoot "/srv/http"
<Directory "/srv/http">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
...
I can verify that the .htaccess files are being read successfully, but If I try to add a http response header in .htaccess like so
<IfModule mod_headers.c>
Header set Test-Header "test"
</IfModule>
the header is not being transferred (I have cache disabled in my browser).
If I set the header in the virtual host files it works fine.
I know that the AllowOverride option is needed.
Maybe someone has an idea what I`m missing here?
Thanks
Offline
Why do you want to use htaccess?? If you can edit the server config, use that.
But in you really must use an htaccess, you need to write it as an htaccess: these are *not* xml files and do not follow the same format as apache cofnigs. There has been (at least previously) a "Header" directive that can be used in htaccess files, e.g.:
Header add Test-Header "test"
EDIT: I suppose apache conf files aren't actually XML either, but they use some xml-like section tags. And apparently htaccess files can also use some xml-like tags to subset what files commands apply to. But just the same, htaccess files and apache config files use different formats / directives - you can't just move content between the two and expect it to work.
Last edited by Trilby (2022-06-13 16:28:27)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for the clarification.
I have a web project that is hosted by a provider where I don`t have access to main server configuration.
So the only way setting individual headers is using .htaccess or php.
The interesting thing is that setting the headers via .htaccess on the "productive" server is working just fine.
And the same file on my test system is not working.
Therefore I think there is something wrong with my local configuration.
Furthermore I don`t see any errors in the log files.
Offline
As my old laptop got broken I did an installation of archlinux on a new machine.
Now the problem is gone.
Response headers are being set from .htaccess.
Offline
Note that apache itself can be configured to use or ignore htaccess files. Generally the admins of shared hosting services enable them as it's expected that users will need to use them. I don't know what the defaults on arch's apache package currently are, but if you have access to the server config itself, it's best to disable htaccess files. The notable exception here is if you are testing content for a shared hosting system on your own arch server (so you replicate similar server configs).
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline