Rewrite image tag from http to https

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 20
Joined: 25 Sep 2014, 13:59

Rewrite image tag from http to https

20 May 2015, 11:48

Hello,

I have a site that is moving to SSL for the entire site. I have the redirect rule in place for this. But we have some images that have the full domain name in the imgage tag. Is there a rewrite rule that will allow me to have these images display in https? I rather not have to change all these image tags. And if it would be easier to have it be for any tag having http://www.mydomain.com, then that would be better. Even though I haven't found any css or javascript using the full domain, we would be covered.

Thanks for you help,
Marc

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite image tag from http to https

21 May 2015, 06:48

Hello Marc,

I guess what you need is the mod_replace module of Ape: http://www.helicontech.com/ape/doc/mod_replace.htm
You can replace the http links on pags with https.

User avatar
Posts: 20
Joined: 25 Sep 2014, 13:59

Re: Rewrite image tag from http to https

22 May 2015, 22:54

Thanks Anton, this put me on the right track. I got it to work with the string, but I would like to have it work with a regex for the maintain the hostname of the URL. I tried a couple of different regex but couldn't get it to work. Here is the example:

ReplaceFilterDefine http_to_https_filter CaseIgnore intype=text/html
ReplacePattern http_to_https_filter "http://dev.mydomain.com" "https://dev.mydomain.com"

SetEnv mod_replace http_to_https_filter

I would like "dev" to be anything and be carried over to the replacement string. I need to maintain the mydomain.com since I don't want to switch other site links over to https. I did try:

ReplacePattern http_to_https_filter "http://(.*).mydomain.com" "https://\1.mydomain.com"

But didn't work.

Any help would be greatly appreciated.

Marc

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite image tag from http to https

24 May 2015, 08:39

Hello,

Please try using the following syntax:

ReplacePattern http_to_https_filter "http://(.*).mydomain.com" "https://$1.mydomain.com"

If it doesn't work, please check the error.log for possible related records.

User avatar
Posts: 20
Joined: 25 Sep 2014, 13:59

Re: Rewrite image tag from http to https

27 May 2015, 17:11

I tried using the $1, but it didn't work. Where is the error.log stored and do I need to set anything to record data? I found an error.log in the helicon ape directory in program files, but nothing regarding this issue was recorded.

Also, is there are hierarchy of modules that can be called? If I run this module (mod_replace) by itself with what I wrote earlier, it will convert the links. But when I include my SEO code for URL rewrites connecting to a database, mod_replace stops working. I tried it above the SEO code and below, same outcome.

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite image tag from http to https

28 May 2015, 15:30

Hello,

>If I run this module (mod_replace) by itself with what I wrote earlier, it will convert the links.
>But when I include my SEO code for URL rewrites connecting to a database, mod_replace stops working.

Oh, so you can make it working under certain conditions? This is interesting...

>Where is the error.log stored and do I need to set anything to record data?

You should put the following line into global httpd.conf:

LogLevel 9

and then check the error.log in Ape install folder.

Also please show me all the rules you have in your Ape config files.

User avatar
Posts: 20
Joined: 25 Sep 2014, 13:59

Re: Rewrite image tag from http to https

28 May 2015, 16:52

As for the mod_replace, I got it to work with (www|sta|dev) and the $1. But using (.*) has not worked. I'm testing various regex values to get this to work since I would like it to be dynamic for any hostname. And mod_replace doesn't work with mod_SEO with how I have the file set up now. Here is the file:

Code: Select all
# Helicon Ape version 3.1.0.138

#replace http://*.mydomain.com with https://*.mydomain.com
ReplaceFilterDefine http_to_https_filter CaseIgnore intype=text/html
ReplacePattern http_to_https_filter "http://(www|sta|dev).mydomain.com" "https://$1.mydomain.com"

SetEnv mod_replace http_to_https_filter

#put these rules into the /forum/.htaccess file
# Enable mod_rewrite and mod_seo for current location
RewriteEngine On
SetEnv mod_seo

# Connect to database
DBDriver mssql
DBDParams "connection string params"

# Prepare SQL queries to find topic or forum name by ID
DBDPrepareSQL "SELECT seo_url FROM seo_url_rewrite  WHERE original_url =@KEY" getSeoURL
DBDPrepareSQL "SELECT original_url FROM seo_url_rewrite  WHERE seo_url =@KEY" getOriginalURL

# Declare database rewrite maps
RewriteMap SeoURL dbd:getSeoURL
RewriteMap OriginalURL dbd:getOriginalURL

SeoCond %{QUERY_STRING} ^([^&]*&)*page=([^&]+)
SeoCond ${SeoURL:$1|NOT_FOUND} !NOT_FOUND
SeoRule (index\.aspx\?event=courses\.main)\&?(.*)? ${SeoURL:$1}\?$2 [Redirect, Scope=A]

SeoCond %{QUERY_STRING} ^([^&]*&)*page=([^&]+)
SeoCond ${SeoURL:$1|NOT_FOUND} !NOT_FOUND
SeoRule (index\.aspx\?event=courses\.featured)\&?(.*)? ${SeoURL:$1}\?$2 [Redirect, Scope=A]

SeoCond %{QUERY_STRING} ^([^&]*&)*page=([^&]+)
SeoCond ${SeoURL:$1|NOT_FOUND} !NOT_FOUND
SeoRule (index\.aspx\?event=search\.activities\&iID=\d+)\&?(.*)? ${SeoURL:$1}/\?$2 [Redirect, Scope=A]

SeoCond %{QUERY_STRING} ^([^&]*&)*queryString=([^&]+|$)
SeoCond ${SeoURL:$1|NOT_FOUND} !NOT_FOUND
SeoRule (index\.aspx\?event=site\.login)\&?(.*)? ${SeoURL:$1}\?$2 [Redirect, Scope=A]

SeoCond ${SeoURL:$1|NOT_FOUND} !NOT_FOUND
SeoRule (index.aspx\?.+)$  ${SeoURL:$1} [Redirect, Scope=A]

RewriteCond %{QUERY_STRING} ^([^&]*&)*page=([^&]+)
RewriteCond ${OriginalURL:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^((.+).html)$ ${OriginalURL:$1} [NC,L, QSA]

RewriteCond %{QUERY_STRING} ^([^&]*&)*page=([^&]+)
RewriteCond ${OriginalURL:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^((.+))/$ ${OriginalURL:$1} [NC,L, QSA]

RewriteCond %{QUERY_STRING} ^([^&]*&)*queryString=([^&]+|$)
RewriteCond ${OriginalURL:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^((.+).html)$ ${OriginalURL:$1} [NC,L, QSA]

RewriteCond ${OriginalURL:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.+)$ /${OriginalURL:$1} [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? / [R=301,L]


User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite image tag from http to https

01 Jun 2015, 10:09

Hello,

>As for the mod_replace, I got it to work with (www|sta|dev) and the $1. But using (.*) has not worked.

Can you provide the error.log file for the rule with (www|sta|dev) and for the rule with (.*). Remember to enable logging in httpd.conf by putting

LogLevel debug

>And mod_replace doesn't work with mod_SEO with how I have the file set up now.

Does nod_seo work on its own?

Can you explain the whole scenario you are trying to make working and how mod_replace, mod_seo and mod_rewrite are supposed interact.

User avatar
Posts: 20
Joined: 25 Sep 2014, 13:59

Re: Rewrite image tag from http to https

03 Jun 2015, 10:29

I added the logging and found that using (.*) only found the first occurence and not all of them. When I used (www|sta|dev) is replaced all.

If I run mod_replace by itself it works, and running mod_seo by itself it works. I did come across this bug when running both on a small dynamic page. This

[2015-06-02 15:13:09.785] [seo_module] (debug) [/files/images/logos/TCYOD_logo.png] Can't create SeoFilter '/files/images/logos/TCYOD_logo.png' is not TextHtm

Thinking this might be the issue mentioned in the mod_seo docs for content-type, I decided to add content-type to the code above mod_seo such as

RewriteEngine On
SetEnv content-type utf-8
SetEnv mod_seo

However that did not eliminate the bug. Running both on a static HTML file worked fine, so its has to be something with the dynamically created content.

We originally used Helicon Ape to assist with converting the dynamic URLs to SEO friendly URLs, which works beautifully. Now we are adding SSL to the site and wanted to find a more convenient way of changing image tags that the client had entered using the full URL with http.

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite image tag from http to https

04 Jun 2015, 13:49

Hello,

>I added the logging and found that using (.*) only found the first occurence and not all of them. When I used (www|sta|dev) is replaced all.

Hmm, this sounds like a bug. I will ask our developers to check this.

Can you please send the logs for (.*) and (www|sta|dev) rules, so I attached them as a proof.

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 20 guests