Skip to main content

Apache redirect www to non-www and HTTP to HTTPS

Comments

4 comments

  • rangka_kacang
    Hello. Write the following to your .htaccess file. This will redirect all traffics from www. (and it's sub directories) with and/or without https to https:// yourdomain.com RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    p/s I have not tested this yet as I'm currently on the move. The 301 redirect is to avoid crawl bots from getting drunk. Thank you.
    0
  • cPanelMichael
    Hello, You may also find the following thread helpful: Thank you.
    0
  • Nirjonadda
    Hello. Write the following to your .htaccess file. This will redirect all traffics from www. (and it's sub directories) with and/or without https to https:// yourdomain.com RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    p/s I have not tested this yet as I'm currently on the move. The 301 redirect is to avoid crawl bots from getting drunk. Thank you.

    Yes are working but only not working one sub directories URL. Please let me know this issue. https://www.mysite.com/xenforo/admin to https://mysite.com/xenforo/admin
    0
  • cPanelMichael
    Hello, Assistance with customizing Mod_Rewrite rules isn't offered, but note you may find more user-feedback to this type of question on a website such as StackOverflow. Or, you may want to consult with a qualified system administrator if you need help customizing Mod_Rewrite rules and the user-feedback you receive is not sufficient. We provide a list of companies offering system administration services at: Thank you.
    0

Please sign in to leave a comment.