• Resolved Ben

    (@benleow)


    I would like to add custom code to the .htaccess file which is located in the target directory. Each time I publish the site, the modified .htaccess got replaced (I have enabled “Generate .htaccess file providing actual HTTP redirects, HTTP status overrides, etc.”). I am wondering is it possible to add a new option in Staatic to include my custom code when I publish my site?

    • This topic was modified 11 months, 1 week ago by Ben.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Team Staatic

    (@staatic)

    Hello Ben,

    Thank you for reaching out. The current version of Staatic makes it a bit tricky to add custom code to the .htaccess file. However, we’ve introduced new features to help with this. We’ve added two filter hooks: staatic_filesystem_apache_config and staatic_filesystem_nginx_config. These allow you to modify the .htaccess and nginx_rules.conf files before saving them.

    To access these new features, you need to update to the latest development version of Staatic. Here’s how to do it:

    1. Go to the WordPress Plugin Directory.
    2. Find Staatic, click on Advanced View.
    3. Scroll down to Advanced Options.
    4. Choose Development Version and click Download.
    5. Install this new version.

    For guidance on using these hooks, check out this example: staatic_filesystem_apache_config.php. You can add this code to your theme’s functions.php file, or as a new file in wp-content/mu-plugins (like staatic_filesystem_apache_config.php).

    If you have any more questions or need help, feel free to ask.

    Thread Starter Ben

    (@benleow)

    Thanks! It works as expected. It would be great if there is textarea for user to input via GUI instead of via functions.php

    Thread Starter Ben

    (@benleow)

    Alternatively, maybe you can provide these options in the GUI:

    1. Redirect non-www URL to www URL and vice versa
    2. Compress components with gzip
    3. Add Expires headers
    Plugin Author Team Staatic

    (@staatic)

    Thank you for your feedback and suggestions. We are glad to hear that the new filter hooks have been working well for you.

    Your suggestion for a GUI textarea for custom code is noted. It’s an interesting idea that could simplify the user experience. We’re also considering your other suggestions, like options for URL redirections and gzip compression.

    If you have any other ideas or feedback, please feel free to share them with us.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding custom code to .htaccess’ is closed to new replies.