I'm sorry for yet another of these posts, but from what I can tell, my question is different than the prevailing http -> https redirects out there.

I want to

      redirect all http://www.mydomain.com traffic to https://www.mydomain.com/wiki

AND

      redirect https://www.mydomain.com   to   https://www.mydomain.com/wiki

Notice the https in my first redirect goal.

For the first redirect, I am able to accomplish this by putting:

RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]

In my httpd.conf file and restarting.

I thought this would also work for my https:// attempts. Notice, I am not including

RewriteCond %{HTTPS} !=on

or anything like that. Yet, still https://www.mydomain.com sends me to my index.html file in my server root.

If I try to put the above Rewrite directives in my httpd-ssl.conf file and restart the server then I get infinite redirects.

What am I doing wrong?

NOTE: For what its worth, /wiki is an alias to /home/Users/myusername/www/wiki (the absolute path to wiki)

UPDATE

Rehash as to what I've tried so far:

Attempt 1:

In httpd.conf:

RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]

In httpd-ssl.conf:

Nothing Rewrite related

Result 1:

Redirects all http traffic to https://www.mydomain.com/wiki Does nothing for https://www.mydomain.com

Attempt 2:

In httpd.conf:

RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]

In httpd-ssl.conf:

RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]

Result 2:

Infinite redirects.

Attempt 3:

In httpd.conf:

RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule !^wiki https://%{SERVER_NAME}/wiki [R,L]

In httpd-ssl.conf:

RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule !^wiki https://%{SERVER_NAME}/wiki [R,L]

Result 3:

Infinite redirects.

Accepted Answer

I found a solution that might not be the most robust but it works for me.

In my httpd-ssl.conf file, under the VirtualHost container, I set the DocumentRoot to point to the directory that I've been trying to redirect to.

<VirtualHost _default_:443>
DocumentRoot "path on my HD where I wanted to redirect all along"
ServerName    All the usual stuff...
...

This takes care of "redirects" (not really redirects anymore) for https transactions

For http (non-ssl) I placed in httpd.conf:

RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]

That seemed to do it.

Written by emiller
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki