0

I am running a website that's not on Wordpress, it is built by another developer using custom framework and it is too terrible. That's what make me crazy now.

Currently, I need to rewrite the request of users to our site as follow:

HTTP to HTTPS redirection goal

I tried many things without luck. %{SERVER_PORT} 80 is one of the things I've tried.

Below is my .htaccess's content:

Options +FollowSymlinks

DirectoryIndex home.html index.php

Options -Indexes

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^www.dongduong.edu\.vn [OR,NC]
RewriteRule ^(.*) https://dongduong.edu.vn/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9_-]+).html&vcb=([a-zA-Z0-9_-]*)&key_oder=([a-zA-Z0-9_-]*)$ index.php?com=$1&vcb=$2&key_order=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&noidi=([a-zA-Z0-9_-]*)&noiden=([a-zA-Z0-9_-]*)&date=([a-zA-Z0-9_-]*)&gia=([a-zA-Z0-9_-]*)$ index.php?com=$1&noidi=$2&noiden=$3&date=$4&gia=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&diadiem=([a-zA-Z0-9_-]*)&sao=([a-zA-Z0-9_-]*)&gia=([a-zA-Z0-9_-]*)$ index.php?com=$1&diadiem=$2&sao=$3&gia=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&p=([0-9]+)$ index.php?com=$1&p=$2    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&curPage=([0-9]+)$ index.php?com=$1&curPage=$2  [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&p1=([0-9]+)$ index.php?com=$1&p1=$2    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&p=([0-9]+)&p1=([0-9]+)$ index.php?com=$1&p=$2&p1=$3    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html$ index.php?com=$1  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)&p=([0-9]+)$ index.php?com=$1&idc=$2&p=$3    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&sapxep=([a-zA-Z0-9_-]+)$ index.php?com=$1&sapxep=$2  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)&sapxep=([a-zA-Z0-9_-]+)$ index.php?com=$1&idc=$2&sapxep=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&sapxep=([a-zA-Z0-9_-]+)$ index.php?com=$1&idl=$4&idc=$2&sapxep=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&id=$3  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+)_([a-zA-Z0-9_-]+).html$ index.php?com=$1&id=$3&idh=$4  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ index.php?com=$1&idhai=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html&p=([0-9]+)$ index.php?com=$1&id=$3&p=$4  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?com=$1&idc=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)/([0-9]+)$ index.php?com=$1&idi=$2&idi=$3&idi=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)/([0-9]+).html$ index.php?com=$1&idl=$2&idl=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&id=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&p=([0-9]+)$ index.php?com=$1&idl=$4&p=$5&idc=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html$ index.php?com=$1&idl=$4&idc=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&idc=$2&id=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&p=([0-9]+)$ index.php?com=$1&idi=$5&p=$6 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html$ index.php?com=$1&idi=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&idc=$2&id=$6 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&p=([0-9]+)$ index.php?com=$1&idh=$6&p=$7 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html$ index.php?com=$1&idh=$6 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&idc=$2&id=$7 [L]

Please help me achieve this.

Thanks for your help!

  • Try this solution http to https apache redirection. RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] – nmr Jul 27 '18 at 16:26
  • Unfortunately, I tried removing everything else except redirect rules but it's not working. Why is the HTTP to HTTPS redirection so complicated? I tried all solutions found on Google but NOTHING works. Below is my .htaccess after removing all other rules (to test redirection only) RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] And where do I need to put these redirection directives? On top, at bottom of htaccess or the position not matter? Thanks again. – chaos thunder Jul 27 '18 at 17:54
  • "I tried many things without luck." - You've not actually stated the specific problem you are having. Does anything happen? Do you get an error? Do you get a redirect loop (and browser warning)? The directive you posted above is invalid and would result in a redirect loop. The directive posted by @RickHellewell looks OK. But if Rick's solution results in the same redirect loop then the "problem" maybe your server config - specifically how your SSL cert is managed. (Btw, this has nothing to do with the "framework" or WordPress for that matter.) – MrWhite Jul 27 '18 at 20:53
  • Thanks for your kind interesting, but I found another solution and it works like a charm. – chaos thunder Jun 20 at 8:57
0

Although the answer in the comment to your question will work (here it is formatted), there are some variations that might be needed depending on your hosting environment, so contact your hosting support for specifics.

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • Unfortunately, I tried removing everything else except redirect rules but it's not working. Why is the HTTP to HTTPS redirection so complicated? I tried all solutions found on Google but NOTHING works. Below is my .htaccess after removing all other rules (to test redirection only) Options +FollowSymlinks DirectoryIndex home.html index.php Options -Indexes RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] – chaos thunder Jul 27 '18 at 17:45
  • Put the rewritecond/rewrite rule at the top, just under the reweriteengine on. Also, contact your host to see their recommendations, as the hosting server OS/configuration may make a difference. – Rick Hellewell Jul 27 '18 at 17:55
  • Thanks for you help, at last, I need to find another solution based on your idea, due to its other complicated redirection rules. But fortunately, it works. Thanks for your kindness. – chaos thunder Jun 20 at 8:58

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.