Перенаправление на CDN

У меня есть установка wordpress на bitnami. Я пытаюсь настроить CDN для содержимого папки wp-content. CDN использует AWS Cloudfront со всем содержимым папки wp-content в корзине S3.
Я не могу заставить apache перенаправить какие-либо запросы на активы в CDN. Я пробовал довольно много вещей, но я просто не могу заставить его работать.

содержимое htaccess.conf.

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/

I have a wordpress installation on bitnami. I am trying to setup a CDN for the contents of the wp-content folder. The CDN utilizes AWS Cloudfront with all the contents of the wp-content folder in an S3 bucket. I can't get apache to redirect any requests for the assets to the CDN. I have tried quite a few things but I just can't get it to work.

contents of htaccess.conf file.

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
<FilesMatch ".(js|css)$">
   ExpiresActive On
   ExpiresDefault "access plus 1 week"
</FilesMatch>
ExpiresDefault "access 1 month"
</IfModule>
# Expires Caching End #

<Directory "/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/akismet">
# Only allow direct access to specific Web-available files.

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order Deny,Allow
    Deny from all
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>

# Akismet CSS and JS
<FilesMatch "^(form|akismet).(css|js)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# Akismet images
<FilesMatch "^(.+).(png|gif)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# compression
<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

#</ifModule>
# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch ".(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files
</Directory>

Contents of http-app.conf

<VirtualHost *:80>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    # Added the following 3 lines to force https
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    #RewriteRule ^wp-content/uploads/(.*)$ https://site.cloudfront.net/wp-content/uploads/$1 [P]
    #Redirect permanent /wp-content/ https:/site.cloudfront.net/wp-content/
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.key"
    SSLCACertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

Contents of httpd-app.conf

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfDefine USE_PHP_FPM>
    <Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300>
    </Proxy>
</IfDefine>

<Directory "/opt/bitnami/apps/wordpress/htdocs">
# Added +Includes for CDN testing. KA
    Options +MultiViews +FollowSymLinks +Includes
# Change from None to All. KA
    AllowOverride All
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>

    <IfDefine USE_PHP_FPM>
       <FilesMatch .php$>
         SetHandler "proxy:fcgi://wordpress-fpm/"
       </FilesMatch>
    </IfDefine>


    RewriteEngine On
# Do not touch the lines below. Added for redierect to www. KA
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    #RewriteBase /wordpress/
    RewriteRule ^index.php$ - [S=1]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
</Directory>

Include "/opt/bitnami/apps/wordpress/conf/htaccess.conf"

If anyone notices any redundant code related to redirects then that's me testing to get this to work.

I can access the contents of the S3 bucket and the cloudfront URL outside the site with no issues.

Any solutions or pointers in the right direction would help.

Thanks!

[NC,NE,R=301]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
<FilesMatch ".(js|css)$">
ExpiresActive On
ExpiresDefault "access plus 1 week"
</FilesMatch>
ExpiresDefault "access 1 month"
</IfModule>
# Expires Caching End #

<Directory "/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/akismet">
# Only allow direct access to specific Web-available files.

# Apache 2.2
<IfModule !mod_authz_core.c>
Order Deny,Allow
Deny from all
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>

# Akismet CSS and JS
<FilesMatch "^(form|akismet).(css|js)$">
<IfModule !mod_authz_core.c>
Allow from all
</IfModule>

<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</FilesMatch>

# Akismet images
<FilesMatch "^(.+).(png|gif)$">
<IfModule !mod_authz_core.c>
Allow from all
</IfModule>

<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</FilesMatch>

# compression
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

#</ifModule>
# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch ".(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files
</Directory>

Содержимое http-приложения.conf

<VirtualHost *:80>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    # Added the following 3 lines to force https
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/(.*) https://%{SERVER_NAME}/

I have a wordpress installation on bitnami. I am trying to setup a CDN for the contents of the wp-content folder. The CDN utilizes AWS Cloudfront with all the contents of the wp-content folder in an S3 bucket. I can't get apache to redirect any requests for the assets to the CDN. I have tried quite a few things but I just can't get it to work.

contents of htaccess.conf file.

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
<FilesMatch ".(js|css)$">
   ExpiresActive On
   ExpiresDefault "access plus 1 week"
</FilesMatch>
ExpiresDefault "access 1 month"
</IfModule>
# Expires Caching End #

<Directory "/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/akismet">
# Only allow direct access to specific Web-available files.

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order Deny,Allow
    Deny from all
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>

# Akismet CSS and JS
<FilesMatch "^(form|akismet).(css|js)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# Akismet images
<FilesMatch "^(.+).(png|gif)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# compression
<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

#</ifModule>
# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch ".(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files
</Directory>

Contents of http-app.conf

<VirtualHost *:80>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    # Added the following 3 lines to force https
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    #RewriteRule ^wp-content/uploads/(.*)$ https://site.cloudfront.net/wp-content/uploads/$1 [P]
    #Redirect permanent /wp-content/ https:/site.cloudfront.net/wp-content/
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.key"
    SSLCACertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

Contents of httpd-app.conf

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfDefine USE_PHP_FPM>
    <Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300>
    </Proxy>
</IfDefine>

<Directory "/opt/bitnami/apps/wordpress/htdocs">
# Added +Includes for CDN testing. KA
    Options +MultiViews +FollowSymLinks +Includes
# Change from None to All. KA
    AllowOverride All
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>

    <IfDefine USE_PHP_FPM>
       <FilesMatch .php$>
         SetHandler "proxy:fcgi://wordpress-fpm/"
       </FilesMatch>
    </IfDefine>


    RewriteEngine On
# Do not touch the lines below. Added for redierect to www. KA
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    #RewriteBase /wordpress/
    RewriteRule ^index.php$ - [S=1]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
</Directory>

Include "/opt/bitnami/apps/wordpress/conf/htaccess.conf"

If anyone notices any redundant code related to redirects then that's me testing to get this to work.

I can access the contents of the S3 bucket and the cloudfront URL outside the site with no issues.

Any solutions or pointers in the right direction would help.

Thanks!

[R,L]
#RewriteRule ^wp-content/uploads/(.*)$ https://site.cloudfront.net/wp-content/uploads/

I have a wordpress installation on bitnami. I am trying to setup a CDN for the contents of the wp-content folder. The CDN utilizes AWS Cloudfront with all the contents of the wp-content folder in an S3 bucket.
I can't get apache to redirect any requests for the assets to the CDN. I have tried quite a few things but I just can't get it to work.

contents of htaccess.conf file.

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
<FilesMatch ".(js|css)$">
   ExpiresActive On
   ExpiresDefault "access plus 1 week"
</FilesMatch>
ExpiresDefault "access 1 month"
</IfModule>
# Expires Caching End #

<Directory "/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/akismet">
# Only allow direct access to specific Web-available files.

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order Deny,Allow
    Deny from all
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>

# Akismet CSS and JS
<FilesMatch "^(form|akismet).(css|js)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# Akismet images
<FilesMatch "^(.+).(png|gif)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# compression
<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

#</ifModule>
# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch ".(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files
</Directory>

Contents of http-app.conf

<VirtualHost *:80>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    # Added the following 3 lines to force https
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    #RewriteRule ^wp-content/uploads/(.*)$ https://site.cloudfront.net/wp-content/uploads/$1 [P]
    #Redirect permanent /wp-content/ https:/site.cloudfront.net/wp-content/
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.key"
    SSLCACertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

Contents of httpd-app.conf

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfDefine USE_PHP_FPM>
    <Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300>
    </Proxy>
</IfDefine>

<Directory "/opt/bitnami/apps/wordpress/htdocs">
# Added +Includes for CDN testing. KA
    Options +MultiViews +FollowSymLinks +Includes
# Change from None to All. KA
    AllowOverride All
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>

    <IfDefine USE_PHP_FPM>
       <FilesMatch .php$>
         SetHandler "proxy:fcgi://wordpress-fpm/"
       </FilesMatch>
    </IfDefine>


    RewriteEngine On
# Do not touch the lines below. Added for redierect to www. KA
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    #RewriteBase /wordpress/
    RewriteRule ^index.php$ - [S=1]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
</Directory>

Include "/opt/bitnami/apps/wordpress/conf/htaccess.conf"

If anyone notices any redundant code related to redirects then that's me testing to get this to work.

I can access the contents of the S3 bucket and the cloudfront URL outside the site with no issues.

Any solutions or pointers in the right direction would help.

Thanks!

[P]
#Redirect permanent /wp-content/ https:/site.cloudfront.net/wp-content/
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
ServerName site.com
ServerAlias www.site.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.key"
SSLCACertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

Содержание httpd-app.conf

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/

I have a wordpress installation on bitnami. I am trying to setup a CDN for the contents of the wp-content folder. The CDN utilizes AWS Cloudfront with all the contents of the wp-content folder in an S3 bucket. I can't get apache to redirect any requests for the assets to the CDN. I have tried quite a few things but I just can't get it to work.

contents of htaccess.conf file.

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
<FilesMatch ".(js|css)$">
   ExpiresActive On
   ExpiresDefault "access plus 1 week"
</FilesMatch>
ExpiresDefault "access 1 month"
</IfModule>
# Expires Caching End #

<Directory "/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/akismet">
# Only allow direct access to specific Web-available files.

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order Deny,Allow
    Deny from all
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>

# Akismet CSS and JS
<FilesMatch "^(form|akismet).(css|js)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# Akismet images
<FilesMatch "^(.+).(png|gif)$">
    <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>

    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</FilesMatch>

# compression
<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

#</ifModule>
# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch ".(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files
</Directory>

Contents of http-app.conf

<VirtualHost *:80>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    # Added the following 3 lines to force https
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
    #RewriteRule ^wp-content/uploads/(.*)$ https://site.cloudfront.net/wp-content/uploads/$1 [P]
    #Redirect permanent /wp-content/ https:/site.cloudfront.net/wp-content/
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.key"
    SSLCACertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt"
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>

Contents of httpd-app.conf

RewriteCond %{HTTP_HOST} ^(www.)?site.com
RewriteCond %{REQUEST_URI} ^(.*).jpg$
RewriteCond %{REQUEST_URI} ^(.*).png$
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301]

<IfDefine USE_PHP_FPM>
    <Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300>
    </Proxy>
</IfDefine>

<Directory "/opt/bitnami/apps/wordpress/htdocs">
# Added +Includes for CDN testing. KA
    Options +MultiViews +FollowSymLinks +Includes
# Change from None to All. KA
    AllowOverride All
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>

    <IfDefine USE_PHP_FPM>
       <FilesMatch .php$>
         SetHandler "proxy:fcgi://wordpress-fpm/"
       </FilesMatch>
    </IfDefine>


    RewriteEngine On
# Do not touch the lines below. Added for redierect to www. KA
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    #RewriteBase /wordpress/
    RewriteRule ^index.php$ - [S=1]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
</Directory>

Include "/opt/bitnami/apps/wordpress/conf/htaccess.conf"

If anyone notices any redundant code related to redirects then that's me testing to get this to work.

I can access the contents of the S3 bucket and the cloudfront URL outside the site with no issues.

Any solutions or pointers in the right direction would help.

Thanks!

[NC,NE,R=301]

<IfDefine USE_PHP_FPM>
<Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300>
</Proxy>
</IfDefine>

<Directory "/opt/bitnami/apps/wordpress/htdocs">
# Added +Includes for CDN testing. KA
Options +MultiViews +FollowSymLinks +Includes
# Change from None to All. KA
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>

<IfDefine USE_PHP_FPM>
<FilesMatch .php$>
SetHandler "proxy:fcgi://wordpress-fpm/"
</FilesMatch>
</IfDefine>

RewriteEngine On
# Do not touch the lines below. Added for redierect to www. KA
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#RewriteBase /wordpress/
RewriteRule ^index.php$ - [S=1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</Directory>

Include "/opt/bitnami/apps/wordpress/conf/htaccess.conf"

Если кто-то замечает какой-либо избыточный код, связанный с перенаправлениями, то это мое тестирование, чтобы заставить это работать.

Я могу получить доступ к содержимому корзины S3 и URL cloudfront вне сайта без проблем.

Любые решения или указатели в правильном направлении помогут.

Спасибо!

1 ответ

  1. Я не уверен, если это поможет вам, но насколько перенаправление идет:

    Когда я перенаправляю на https из http-версии моего сайта, я использую эту строку в моем apache2.conf файл:

    Redirect "/" "https://www.version.of.my.site"
    

    Я заметил ваши строки перенаправления в вашем http-приложении.conf комментируются.