Results 1 to 6 of 6

Thread: apache2 - add custom response header

  1. #1
    Join Date
    Sep 2015
    Location
    Italia
    Beans
    138
    Distro
    Ubuntu 18.04 Bionic Beaver

    apache2 - add custom response header

    Dear users,

    I want to add a custom response header if the file requested has a particular extension.

    I think the directives will be written in httpd.conf.

    Example:
    all files .txt will have encoding utf-8, so I want to instruct the client browser the encoding.

    Is it possible? And how?

    Thanks

  2. #2
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: apache2 - add custom response header

    In the definition for the virtual host use a Files directive with AddDefaultCharset

    Code:
    <VirtualHost *:80>
    [stuff]
    
    <Files "*.txt">
    AddDefaultCharset utf-8
    </Files>
    
    [more stuff]
    </VirtualHost>
    https://httpd.apache.org/docs/2.4/mod/core.html#files

    https://httpd.apache.org/docs/2.4/mo...defaultcharset

    You can force the entire server to use utf-8 by editing /etc/apache2/conf-available/charset.conf.
    Last edited by SeijiSensei; January 21st, 2019 at 03:37 PM.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  3. #3
    Join Date
    Sep 2015
    Location
    Italia
    Beans
    138
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: apache2 - add custom response header

    I found in /etc/apache2/conf-available/charset.conf this line:
    Code:
    #AddDefaultCharset utf-8
    I have just uncommented it and restarted apache2 service and now it works.

    But now, if I want to add a particular http response header, like this:
    Code:
    X-Dachi: dam034
    How can I do it?

    Thanks

  4. #4
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: apache2 - add custom response header

    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  5. #5
    Join Date
    Sep 2015
    Location
    Italia
    Beans
    138
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: apache2 - add custom response header

    And if I want to overwrite some apache default response headers?

    Like Server response header?

    Thanks

  6. #6
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: apache2 - add custom response header

    That's what documentation is for. Apache's is pretty extensive.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •