1

Previously I had a website implemented as a single page application on S3, and it had a page pointing to a list of tools. The URL for this list was: example.com/tool/<tool-name>

To expand the features of my website, I redid the DNS so that this old site is now sitting on a subdomain: tools.example.com/tool/<tool-name> (the new site, that is, example.com, is now on Lighthouse/Wordpress).

As there are still a bunch of links around the web referencing URLs in the tool list of the old site, I would like to write a redirect on Bitnami.

I've already asked for help on this and was told to do the following, but the redirect still doesn't seem to work when I go to example.com/tool/<tool-name>:

  1. Modify /opt/bitnami/apps/wordpress/conf/httpd-app.conf by adding the following rule to the bottom of the file: RewriteEngine on RewriteCond %{REQUEST_URI} ^/tool/(.*)$ RewriteRule ^(.*)$ https://tools.example.com/tool/$1 [P,L]

  2. sudo /opt/bitnami/ctlscript.sh apache restart

Is this pattern correct, or am I writing to the right file?

EDIT I changed the redirect code above slightly to reflect feedback in the comments. It is redirecting to https not http and I changed the last bit of code to [P,L] from [R=301,L]

orlando21
  • 307
  • 1
  • 5
  • 15
  • Bitnami Engineer here. The `apps/wordpress/conf/httpd-app.conf` file includes the configuration to serve WordPress properly and you can add more configuration there as this file is included in the default VirtualHosts of Apache. You can also add those lines in the main VirtualHost configuration defined in the `/opt/bitnami/apache2/conf/bitnami/bitnami.conf` file and restart Apache after that. I hope this information helps – Jota Martos Sep 21 '18 at 13:47
  • I didn't know I could add in two places. However, still no redirect takes place (the browser still lands on `example.com/tool/` and reports a 404). – orlando21 Sep 22 '18 at 05:33
  • Did you set the Rewrite lines in the main configuration file of Apache? – Jota Martos Sep 24 '18 at 14:19
  • It seems the file referred to is `/opt/bitnami/apache2/conf/httpd.conf`. Would I need to wrap the redirect command in some markup like ``? – orlando21 Sep 25 '18 at 07:55

1 Answers1

0

I just tested this change in the Bitnami solution and it worked properly, can you try it?

  • Remove the changes from the /opt/bitnami/apps/wordpress/conf/httpd-app.conf file
  • Edit the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file and include the Rewrite* lines the VirtualHost of the port 80

    ...
    <VirtualHost _default_:80>
      DocumentRoot "/opt/bitnami/apache2/htdocs"
      RewriteEngine on
      RewriteCond %{REQUEST_URI} ^/tool/(.*)$
      RewriteRule ^(.*)$ http://google.com [P,L]
      ...
    

You can also add those lines in the VirtualHost block of the port 443 in the same file.

  • Restart Apache

    sudo /opt/bitnami/ctlscript.sh restart apache
    

As you can see, in my example, Apache is redirecting to google.com but you can redirect to any URL.

Jota Martos
  • 4,548
  • 3
  • 12
  • 20
  • Just to confirm, I inserted the redirect code in both places of that file (for ports 80 and 443) and the code in both places is sandwiched between the and markup tags. I restarted apache. Now am getting a 500 server error `[proxy:error] AH00961: HTTPS: failed to enable SSL support for ` with also a `[ssl error] AH01961: SSL proxy requested for localhost:443 but not enabled [Hint: SSLProxyEngine]` However I have enabled SSL for that subdomain and it works with https. – orlando21 Sep 25 '18 at 16:57
  • Could you also try adding `SSLProxyEngine on` inside the VirtualHost 443 section? – Javier Salmeron Sep 27 '18 at 07:36
  • I added that line right below `SSLEngine on`, restarted Apache, and now there are no errors but the actual redirect doesn't happen (i.e. it displays `example.com/tool/` rather than redirecting to `tools.example.com/tool/`. I edited my question above to show the rewrite code I'm using... I guess that's correct? – orlando21 Sep 27 '18 at 08:21
  • Weird, as the solution from my colleague Jota seemed to work. Could you try enabling the rewriterule debugging? https://stackoverflow.com/questions/9632852/how-to-debug-apache-mod-rewrite. You need to change the log level in `/opt/bitnami/apache2/conf/httpd.conf` and then restart Apache. In `/opt/bitnami/apache2/logs/error_log` you should see the debugging – Javier Salmeron Sep 28 '18 at 07:34
  • Thanks @JavierSalmeron, actually I should be implementing the redirect not on `tools.example.com` (new server) but on the old server `example.com` (according to advice I got on another forum). Reason is that both old and new server have different IPs. The old server isn't implemented on Bitnami, so I have to now look into that. – orlando21 Oct 02 '18 at 17:06