.htaccess - 重写不适用于 ssl

标签 .htaccess mod-rewrite ssl https prestashop

我想不通,似乎 Prestashop url 重写在 url:s 中使用 ssl (https) 时停止工作,基本 url 工作正常,如 https://www.domain.se但例如,当在图像 url 上使用 https 时,图像不会加载。 这是 htaccess 文件,也许有人可以看到任何明显的错误?

# eTiendas.co Custom .htaccess prefix start
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.se$ [NC]
RewriteRule ^(.*)$ http://www.domain.se/$1 [L,R=301]
# eTiendas.co Custom .htaccess prefix end# eTiendas.co Custom .htaccess prefix start
RewriteRule ^sv(.*)?$ http://www.domain.se$1 [R=301,L]
RewriteRule ^en(.*)?$ http://www.domain.se$1 [R=301,L]
# eTiendas.co Custom .htaccess prefix end

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code    outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# Images
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]

# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^www.domain.se$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

FileETag INode MTime Size
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

最佳答案

由于解决方案不是作者贴出来的:

更改以下文件 (/etc/apache2/sites-available/default-ssl):

 <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride none
            Order allow,deny
            allow from all
    </Directory>

对此:

 <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
    </Directory>

还记得指定证书文件(在同一个虚拟主机文件中)以及我们运行:

a2enmod ssl

a2ensite 默认 ssl

服务apache2重启

关于.htaccess - 重写不适用于 ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16147169/

相关文章:

html - .htaccess 文件的位置

php - 如何使用 php 和 htaccess 创建 seo 友好的 url?

css - 如何忽略使用 .htaccess 重写 css 文件

c++ - 您如何使用 WinHTTP 通过自签名证书执行 SSL

ssl - 如何通过命令方式从PEM文件中分别只获取证书部分和私钥部分?

html - 使用 .htaccess 删除 .html 和 .php 扩展名

apache - 使用 .htaccess 重写服务器特定 URL 的方法不遵守 RewriteCond

node.js - gulp 和 url 重写

php - 使用 .htaccess 为子域强制使用 SSL HTTPS

android - 自定义 SSLSocketFactory 不使用自定义 trustmanager