4

I recently configured by website to direct all traffic through https. I did this by modifying the vhost file to show this

<VirtualHost *:80>
    DocumentRoot "/srv/http/example"
    ServerName example.com
    Redirect permanent / https://example.com/
</VirtualHost> 

This works fine when I go to the root of the site i.e. example.com, however when I try to go to a subdirectory I get a weird break in the url. For example if I type example.com/blog it tries to redirect to https://example.comblog. What is going on here?

2
  • I can't reproduce this error if the Redirect line become Redirect permanent / https://example.com (e.g without trailing slash). With your configuration above, the redirection works properly. – masegaloeh May 9 '14 at 9:48
  • I tried removing the trailing / and using RedirectMatch permanent ^/(.*)$ https:/example.com/$1 and neither worked. – stmfunk May 9 '14 at 10:55
4

I managed to solve the problem by changing:

https://example.com/

to

https://example.com\/

This seems to have solved the problem, I assume that at some point Apache stripped off the slash.

0
1

For redirecting a TLS/SSL site to a non-TLS site, see the details below:

Adding a trailing slash, and escaping it with a backslash restores the missing slash.

I found that my particular site needed the redirect in both virtual hosts (*:80 and *:443) but the TLS one was not working properly. The following added to both virtual hosts fixed the issue.

Redirect permanent "/" http://example.com\/  

Note: The apache documentation shows adding quotes around everything. In my case the above worked just fine, allowing pages in the URL to be resolved as expected. Source: https://httpd.apache.org/docs/2.4/en/rewrite/avoid.html

Examples extrapolated from Source:

Redirect "/one/" "http://one.example.com/"
Redirect permanent "/" "http://example.com/"

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.