0

Hi how can I redirect toptangiy.com and www.toptangiy.com redirect to https://www.toptangiy.com

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^toptangiy.com$
RewriteRule (.*) https://www.toptangiy.com/$1 [R=301,L]

</IfModule>

This is my htaccess after this codes site write err too many redirects

Jr Aa
  • 25
  • 7
  • Your first condition doesn't include www in the redirect. – Ultimater Sep 12 '18 at 05:51
  • I would suggest that you do a search on the subject before posting. This is a common question with _many_ examples here on SO alone.Try: _"apache redirect to https"_. I'm quite sure you will find some that fits your case more or less exactly. If not, take one that works and modify it to fit your needs. – M. Eriksson Sep 12 '18 at 06:04
  • i am need only correct codes for redirecting [link](https://toptangiy.com) – Jr Aa Sep 12 '18 at 06:07
  • this will help in redirecting all traffic to https `RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}` – 7060965 Sep 12 '18 at 06:08
  • Follow the following link: [Redirecting from HTTP to HTTPS with PHP](https://stackoverflow.com/a/5106355/6048160) – Gurpreet Kaur Sep 12 '18 at 06:12
  • You can follow [http to https through .htaccess](https://stackoverflow.com/questions/10489895/http-to-https-through-htaccess) – Gurpreet Kaur Sep 12 '18 at 06:17

1 Answers1

1

If the task is enforce https and www for a domain, it's a very common task, and there's lots of answers on StackOverflow for it. But as far as the way I'd write this for your case, I'd use:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Enforce https for toptangiy.com
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www.toptangiy.com$
    RewriteRule (.*) https://www.toptangiy.com/$1 [R=301,L]

    # Enforce www for toptangiy.com
    RewriteCond %{HTTP_HOST} ^toptangiy.com$
    RewriteRule (.*) https://www.toptangiy.com/$1 [R=301,L]
</IfModule>
Ultimater
  • 4,647
  • 2
  • 29
  • 43
  • i remove that and same problem – Jr Aa Sep 12 '18 at 06:10
  • i can write you my admin panel password you can control that ? – Jr Aa Sep 12 '18 at 06:13
  • @JrAa Made an adjustment. Due to a permanent 301 redirect being used, browsers will cache previous redirects.Try testing on http://websniffer.cc/ – Ultimater Sep 12 '18 at 06:20
  • @7060965 That's simply incorrect. The rewrite rule only matches the `/` and does not include the domain. When testing on htaccess.madewithlove.be you need to include the scheme in the request url you're testing on as noted on the site. – Ultimater Sep 12 '18 at 06:23
  • @JrAa don't share cpanel user name and password in comments. if you trust some one then share on email instead of comments or public platform – Bilal Ahmed Sep 12 '18 at 06:26
  • this is my htaccess my domain redirecting to `http://site name` to https://www.sitename only i need toptangiy.com and www.toptangiy.com redirect too `https://www.toptangiy.com` ` RewriteEngine On RewriteCond !{HTTPS} off RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] this is correct only http://www.toptangiy.com not redirect too https://www.toptangiy.com – Jr Aa Sep 12 '18 at 06:27
  • Bilal Ahmed thank you ) – Jr Aa Sep 12 '18 at 06:32
  • @JrAa See updated post. Test using http://websniffer.cc/ – Ultimater Sep 12 '18 at 06:32
  • HTTP Request Header Connect to 188.93.212.115 on port 443 ... ok GET / HTTP/1.1 User-Agent: WebSniffer/1.0 (+http://websniffer.cc/) Host: www.toptangiy.com Accept: */* Referer: http://websniffer.cc/ HTTP Response Header Name Value HTTP/1.1 200 OK Server: nginx/1.14.0 Date: Wed, 12 Sep 2018 06:38:34 GMT Content-Type: text/html; charset=utf-8 Content-Length: 22398 Connection: keep-alive X-Powered-By: PHP/5.6.36 – Jr Aa Sep 12 '18 at 06:39
  • @JrAa nginx? Might verify your setup is properly funneling to apache so it can read .htaccess files. If it's straight nginx, it won't read .htaccess files (apache only). Also might need to clear your cache due to 301 redirects being used and test in incognito. Hence my reason for suggesting websniffer.cc – Ultimater Sep 12 '18 at 07:33
  • i clerar cache no worked axax – Jr Aa Sep 12 '18 at 17:47
  • @JrAa I don't believe you're using the code in my post... Please test on http://websniffer.cc/ The behavior I currently see for whatever setup you have on your domain is both: `https://toptangiy.com/` and `http://toptangiy.com/` are permanently redirecting to `https://www.toptangiy.com/` But `http://www.toptangiy.com/` (has www but no https ) is NOT redirecting... The .htaccess code in my post should redirect this. See for yourself on https://htaccess.madewithlove.be/ When you see the proper behavior on http://websniffer.cc/ then only attempt to clear your cache. – Ultimater Sep 13 '18 at 02:08
  • I can write you my password and login do you can help me give me your email adres – Jr Aa Sep 13 '18 at 05:09
  • i write to your e-mail adres – Jr Aa Sep 13 '18 at 05:47
  • Ultimater thank you so much) – Jr Aa Sep 13 '18 at 08:22