Skip to content

Instantly share code, notes, and snippets.

@JasvinderSingh1
Last active July 30, 2019 14:28
Show Gist options
  • Save JasvinderSingh1/0db75937185090cb25063c11db51deef to your computer and use it in GitHub Desktop.
Save JasvinderSingh1/0db75937185090cb25063c11db51deef to your computer and use it in GitHub Desktop.
How to redirect http://domain.com to https://www.domain.com?
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
*********************
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
**** To remove .php from URL start ****
RewriteEngine On
RewriteBase /admin/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
-> Be sure to change the "RewriteBase", write "/" if you are putting it in root
**** To remove .php from URL end ****
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment