1

I currently have rewrite working on example.com, the entire site is HTTPS, using this:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

I need a lot of files on this exact same website, accessible via a second domain name, and over HTTP, for example: http://example.net/files/....

I tried adding example.net as a ServerAlias but of course this just redirect and then rewrites to https://example.net/files

I copied the rewrite rule from the internet, and am unsure of the correct way to modify it.

I was thinking along the lines of changing rewrite rule to something along the lines of:

RewriteRule ^example.com/?(.*) https://example.com/$1 [R,L]

so that URLs are only rewritten if they include example.com Then would I need a rewrite rule for the TLD domain itself and not this wildcard entry?

Please can somebody help with the correct way to achieve this, so that requests to the ServerAlias (example.net) are not rewritten?

2 Answers 2

2

If you want to point two domains to the same content. eg. example.com and example.net. Then create separate virtual hosts for each domain but point them to same document root. Add one VirtualHost entry with 80 for HTTP (http://example.com) and another domain entry with 443 with HTTPS (https://example.net) and assign require SSL entries.

1
  • Yes. Except I think you got the domains the wrong way round... you'd need 3 virtual hosts: example.com:80 (that simply redirects to 443), example.com:443 and example.net:80.
    – MrWhite
    Jul 5, 2017 at 14:26
0

As Sunil suggests, you can create separate virtual hosts and the SSL redirect would then only occur in the first one (ie. example.com port 80). (You can also avoid mod_rewrite and just use a single mod_alias Redirect, which would be preferable.)

However, you can also do what you were suggesting and create a ServerAlias for example.net (your other domain) and include a condition (ie. REwriteCond directive) in your current redirect that only redirects the example.com domain. For example:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Note that this should really be a 301 (permanent) redirect, once you have confirmed it's working OK. ie. [R=301,L].

You must log in to answer this question.

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