Title: htaccess Fileș in document directories redirect to http not https
Last modified: June 24, 2022

---

# htaccess Fileș in document directories redirect to http not https

 *  [Andy Macaulay-Brook](https://wordpress.org/support/users/andymacb/)
 * (@andymacb)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/htaccess-files-in-document-directories-redirect-to-http-not-https/)
 * The problem from [https://wordpress.org/support/topic/mixed-content-error-when-downloading-attachments/](https://wordpress.org/support/topic/mixed-content-error-when-downloading-attachments/)
   rears its head again.
 * On our document pages on the front end, links to document pages are of the form:
 * [https://www.universitychairs.ac.uk/docs/freedom-of-speech-presentation-slides/](https://www.universitychairs.ac.uk/docs/freedom-of-speech-presentation-slides/)
 * And on this page the linked attachment is [https://www.universitychairs.ac.uk/wp-content/files/bp-attachments/2252/FoS-CUC-Feb-2021.pdf](https://www.universitychairs.ac.uk/wp-content/files/bp-attachments/2252/FoS-CUC-Feb-2021.pdf)
 * The plugin default htaccess redirects this to a plain http URL:
 * [http://www.universitychairs.ac.uk/docs/freedom-of-speech-presentation-slides/?bp-attachment=FoS-CUC-Feb-2021.pdf](http://www.universitychairs.ac.uk/docs/freedom-of-speech-presentation-slides/?bp-attachment=FoS-CUC-Feb-2021.pdf)
 * And in modern Chrome and Edge this blocks the download following their new mixed
   content policies, even if http is redirected to https again in the chain of redirects.
 * Can you change the htaccess to return https URLs if the initial request uses 
   https? Since the Apache behaviour is to run the plugin htaccess before any others
   further up the directory hierarchy, I think this is the only place to fix this
   problem.
 * Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Andy Macaulay-Brook](https://wordpress.org/support/users/andymacb/)
 * (@andymacb)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/htaccess-files-in-document-directories-redirect-to-http-not-https/#post-15767971)
 * I’ve found the filter hook bp_docs_attachments_generate_rewrite_rules and have
   adjusted the rewrite rules.
 * However, there doesn’t seem to be an easy way to bulk regenerate the htaccess
   files. How would I get a document loop in my small fix plugin using your public
   function calls?
 * Thanks.
 *  Plugin Author [David Cavins](https://wordpress.org/support/users/dcavins/)
 * (@dcavins)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/htaccess-files-in-document-directories-redirect-to-http-not-https/#post-15768028)
 * hi Andy,
 * Obviously you’re digging in to this problem. Maybe you can help us resolve the
   http:// protocol issue. Do you know why your links were being generated as [http://](https://wordpress.org/support/topic/htaccess-files-in-document-directories-redirect-to-http-not-https/?output_format=md)?
   We use `get_permalink()` to fetch the doc URL (and that uses `home_url()`), so
   why are yours http? Is your home or site url set to http? It’s a mystery; mine
   are always https.
 * Regarding creating new htaccess, the simplest thing to do would be to loop through
   all non-public docs and save them. Then this action will be triggered in BP_Docs_Attachments:
   `
   add_action( 'bp_docs_doc_saved', array( $this, 'check_privacy' ) );`
 *  Thread Starter [Andy Macaulay-Brook](https://wordpress.org/support/users/andymacb/)
 * (@andymacb)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/htaccess-files-in-document-directories-redirect-to-http-not-https/#post-15768098)
 * It’s purely the htaccess file rewrite rule. I set up an empty directory with 
   a couple of test files, accessed one using https and the redirect generated was
   http and not https.
 * My fix on the site concerned is rather blunt. After a day without access to their
   documents, I was getting a bit frazzled. So my substitute rewrite rule uses https
   hardcoded and also the hostname. Something like:
 *     ```
       RewriteEngine On
       RewriteRule (.+) https://example.com/docs/my-doc-slug/?bp-attachment=$1 [R=302,NC]
       ```
   
 * It would have been harder if you hadn’t put in the filter hook for the rewrite
   rules and passed the whole doc object!
 * If the default htaccess rewrite rule is falling back to http then I can only 
   think it’s something in my ISP’s configuration, but it seems to me that with 
   more thought than I had left a rewrite rule that copies the schema and host from
   the request would do the trick?
    -  This reply was modified 3 years, 11 months ago by [Andy Macaulay-Brook](https://wordpress.org/support/users/andymacb/).
 *  Plugin Author [David Cavins](https://wordpress.org/support/users/dcavins/)
 * (@dcavins)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/htaccess-files-in-document-directories-redirect-to-http-not-https/#post-15768146)
 * Can you see what value is returned by `is_ssl()` on your setup? What about for`
   home_url()` with no arguments?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘htaccess Fileș in document directories redirect to http not https’ is
closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/buddypress-docs.svg)
 * [BuddyPress Docs](https://wordpress.org/plugins/buddypress-docs/)
 * [Support Threads](https://wordpress.org/support/plugin/buddypress-docs/)
 * [Active Topics](https://wordpress.org/support/plugin/buddypress-docs/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/buddypress-docs/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/buddypress-docs/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [David Cavins](https://wordpress.org/support/users/dcavins/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/htaccess-files-in-document-directories-redirect-to-http-not-https/#post-15768146)
 * Status: not resolved