I want apache to:
- redirect http users to https
- if they access http(s)://example.com/1234 redirect to /view/1234
I have tried different flavours but cannot get it work. When a user access the website, they get redirected to https://, however I cannot get the /{numeric} to redirect to add /view/. The numeric rule was working okay until I put the https redirect on.
I have tried it with RewriteCond %{HTTPS} = on, but this causes 500 errors.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://domain.example.org/$1 [R,L]
RewriteRule ^(\d+)$ https://domain.example.org/view/$1 [R=301,L]
Will this not work for you?
Try this to test:
http://htaccess.madewithlove.be/
Ok it sounds like you actually want something like this:
Replace first RewriteCond with:
This is going to be an off the cuff answer, but, I believe the rewrite rules match in a first come/first serve basis. Since the path structure changes, I'll bet your http://domain.example.org/1234 users are getting redirected to the https equivalent but without the path change. Try switching the order of the rules and you'll get closer to a full solution.
If that doesn't work, let me know and I'll fire up an Apache instance and we'll see what we can get working in tandem.
Thanks for your help.
I finally have it working. I used the following:
So any numeric requests have /view added on, any attempts to access the site with http:// gets forwarded to https://. Seems to work well.