Answers for "example of .htaccess File"

2

.htaccess

//Force HTTPS

RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

//Force www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^htmlg\.com [NC]
RewriteRule ^(.*)$ http://www.htmlg.com/$1 [L,R=301,NC]

//Force non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.htmlg\.com [NC]
RewriteRule ^(.*)$ http://htmlg.com/$1 [L,R=301]

//Custom Error Pages
ErrorDocument 500 "Sorry, something went wrong!"
ErrorDocument 401 https://htmlg.com/404/
ErrorDocument 404 404error.html

//Redirect Entire Site
Redirect 301 / https://htmlg.com/

//Permanent Page Redirect
Redirect 301 /oldlink.html https://htmlg.com/help/
Redirect 301 /oldlink https://htmlg.com/about/

//Alias Directory
RewriteEngine On
RewriteRule ^source_directory/(.*) target_directory/$1

//Remove .php Extension
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]

//Block IP Address
Order deny,allow
Allow from all
Deny from 123.123.123.123
Deny from 123.123.123.123

//Allow Access From Only One IP
# Require all denied
# Require ip 123.123.123.123
Posted by: Guest on August-05-2021
0

.htaccess

# Browser Caching
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 3 days"
Posted by: Guest on June-28-2020

Browse Popular Code Answers by Language