Mobile app version of vmapp.org
Login or Join
Sent6035632

: HTTPS redirect doesn't appear to follow .htaccess RewriteRule, how can I fix this? I am redirecting example.com to sample.com/?example, so that I can have a modal popup saying, example has changed

@Sent6035632

Posted in: #301Redirect #Apache #Htaccess #Https #Redirects

I am redirecting example.com to sample.com/?example, so that I can have a modal popup saying, example has changed its name to sample.

It works fine for HTTP redirects from example.com, and almost everything works for HTTPS redirects from example.com, except for these two things (applying only to the redirects from example.com):


In the address bar, it will still say example.com, but show the page for sample.com. Whenever a link is clicked on this page, the problem is fixed and it then shows sample.com in the address bar.
It will not keep the query that I add (?example=1).


Here are my .htaccess rules:

RewriteCond %{HTTPS} ^example.com$ [OR]
RewriteCond %{HTTPS} ^www.example.com$
RewriteRule (.*)$ www.sample.com/?example=1 [R=301,L]


How can I fix these so that when I go to example.com, it goes to sample.com?example=1

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent6035632

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

You must have more directives in your .htaccess in order to do the complete HTTP and HTTPS redirection. So, filling in the gaps...

For the sake of simplicity I've assumed you don't have any other subdomains (apart from www). So you are redirecting everything at example.com to sample.com.
# Redirect example to sample RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} example.com
RewriteRule (.*) www.sample.com/?example=1 [R=301,L]

# Redirect example to sample RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} example.com
RewriteRule (.*) www.sample.com/?example=1 [R=301,L]


%{HTTPS} is always set (regardless of whether SSL is enabled or not) and simply contains the value "on" or "off".

The trailing $ (end of pattern marker) on the RewriteRule pattern is not required. And the 2nd argument to RewriteCond (the CondPattern) is a regular expression (most of the time) so the dots should really be escaped, otherwise they match anything.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme