1

I would like to redirect all URLs to https on my host and root folder to sub-folder.

My configuration:

Redirect permanent / https://myhost.com/ 
RedirectMatch ^/$ /sub-folder/

The first redirect works well, all http requests are redirected to https, but the second one does nothing.

Any advice, please?

Thanks.

2
  • Where did you put this configuration? Jan 9, 2019 at 22:17
  • To /etc/apache/sites-available/myhost.conf (symlink to sites-enabled ofc).
    – dannyx
    Jan 9, 2019 at 22:33

2 Answers 2

1

It appears the problem is with your first rule:

Redirect permanent / https://myhost.com/

Which could be changed to:

Redirect permanent http://myhost.com/ https://myhost.com/

Additionally, the regular expression doesn't seem to work unless it's inside quotes, so ^/$ should be changed to "^/$"

The second redirect is not observed because the first redirect occurs an infinite number of times.

I was able to debug this by adding a couple of entries to my /etc/hosts file as follows:

127.0.0.1 kerneldeimos.local
127.0.0.1 subdomain.kerneldeimos.local

I then added your rewrite rules (using a subdomain instead of HTTPS for convenience):

Redirect permanent / http://subdomain.kerneldeimos.local
RedirectMatch "^/$" /sub-folder/

It worked after I changed my config to the following:

Redirect permanent http://kerneldeimos.local http://subdomain.kerneldeimos.local
RedirectMatch "^/$" /sub-folder/
1

After some research, I handled it. Problem was that first redirect was redirected to port 443 so the second redirect has to be managed in VirtualHost:443. And as you said, the quotes are required in RedirectMatch directive.

Thank you very much.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .