title: htaccess Canonical URL and HTTP->HTTPS redirects (custom url)
body: <p>I hope so you could help me solve this issue. I am trying to setup my apache server redirects, but without success. I am trying to do this at at once:</p>
  
  <ol>
  <li><a href="http://www.example.com" rel="nofollow noreferrer">http://www.example.com</a> -> redirects to -> https:/ /example.com</li>
  <li><a href="http://example.com" rel="nofollow noreferrer">http://example.com</a> -> redirect to -> https:/ /example.com</li>
  <li><a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a> -> redirect to -> <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a></li>
  <li>(if the URL contains file extensions like .php/.html I want to remove them) LIKE: https:/ /example.com/portfolio.php -> to be replaced to -> <a href="https://example.com/portfolio" rel="nofollow noreferrer">https://example.com/portfolio</a></li>
  <li>URLs can also contain 1 or 2 URL params and I want to replace the url separated by / like that: <a href="https://example.com/portfolio.php?id=1&amp;t=Max" rel="nofollow noreferrer">https://example.com/portfolio.php?id=1&amp;t=Max</a> -> to be replaced to ->
  <a href="https://example.com/portfolio/1/Max" rel="nofollow noreferrer">https://example.com/portfolio/1/Max</a></li>
  </ol>
  
  <p>Also all redirects should use R=301 if possible.</p>
  
  <p>Here is what I have so far, but it's not working.</p>
  
  <pre><code>RewriteEngine On
  
  RewriteCond %{SERVER_PORT} 80
  
  RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
  
  RewriteRule ^portfolio/(\d+)/(.*) portfolio.php?id=$1 [QSA,L] 
  
  RewriteRule ^portfolio portfolio.php [QSA,L]
  
  RewriteRule ^about about.php [QSA,L]
  </code></pre>
  
  <p>Please help me solve this issue. It took me so much reading but never did it right. The main problem is that Google Crawlers recognize my pages as duplicated, and I have canonical URL problems which I want to resolve. </p>
  
  <p>Thank you for the help!</p>