#301 Permanent redirect for sub-folder to main domain
RewriteEngine On
RedirectMatch permanent ^/subfolder/$ http://www.yourdomain.com/
#302 Temp redirect
RewriteEngin On
RedirectMatch 302 ^/subfolder/$ http://www.yourdomain.com/
#Redirect from http://www.yourdomain.com/subfolder/(post-url) to http://www.yourdomain.com/(post-url)
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com
RewriteRule ^subfolder/(.*)$ http://www.yourdoamin.com/$1 [L,R=301]
#Redirect from subdomain’s subdirectory (sub.yourdomain.com/subfolder/(post-url) to http://www.mysample.com/(post-url)
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub.yourdomain.com
RewriteRule ^subfolder/(.*)$ http://www.yourdomain.com/$1 [L,R=301]
#Direct root domain to sub-folder index file
DirectoryIndex welcome/index.html
#Redirect old domain to new domain with exact same URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
#Redirect old sub-directory url to specific new url
RedirectMatch 301 ^/sub1(.*)$ https://yourdomain.com/new-url.html
#Multiple sub-directories
RedirectMatch 301 ^/sub1/sub2/sub3(.*)$ https://yourdomain.com/new-url.html
#Redirect old file path to new file path
Redirect /v1/en/store-locator.html https://www.newlink.com/en/store-locator.html
#This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/
Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts
Monday, June 11, 2018
Wednesday, June 7, 2017
Useful htaccess (HyperText Access) configuration to control Apachee Web server
.htaccess is a configuration file for use on web servers running the Apache Web Server software and below is some of useful configuration.
1. Create .htaccess file with notepad or any text editor and paste it below code
2. Upload it into your web server and remove ".txt" after uploaded
For more info: http://www.htaccess-guide.com/
+============================+
# Note: Hash sign (#) for comments
#Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
#Redirect non-www to www (Option 2)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Change .php extension to .html
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [nc]
#Force https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Force https (option 2)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#Force https (option 3)
#Force www / https
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301,NC]
# Directory Index: You can change a default index file from another directory (eg. index.php is inside welcome folder)
# DirectoryIndex welcome index.php
# Access Control: You can Deny / Allow over specific IP address and it's useful when you are doing site updates
Order deny,allow
# Deny all public access
Deny from all
# Allow your IP address so only you can see the site
Allow from xxx.xx.xx.xxx
# Redirect your users to a temporary an error page, welcome page or maintenance page during site update/development with your custom page
ErrorDocument 403 /welcome/comingsoon.php
# Prevent Directory Browsing (Disable/Enable)
# To Disable
Options All -Indexes
# To Enable
# Options All +Indexes
# Create custom error pages and do not forget to create related error html file in source
# And you can extend this like as well:
# ErrorDocument 400 /400.html #400 - Bad Request
# ErrorDocument 401 /401.html #401 - Not Authorized
# ErrorDocument 403 /403.html #403 - Forbidden
# ErrorDocument 404 /404.html #404 - Not Found
# ErrorDocument 500 /500.html #500 - Internal Server Error
# ErrorDocument 502 /502.html #502 - Bad Gateway
# ErrorDocument 504 /504.html #504 - Timeout Error
+============================+
1. Create .htaccess file with notepad or any text editor and paste it below code
2. Upload it into your web server and remove ".txt" after uploaded
For more info: http://www.htaccess-guide.com/
+============================+
# Note: Hash sign (#) for comments
#Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
#Redirect non-www to www (Option 2)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Change .php extension to .html
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [nc]
#Force https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Force https (option 2)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#Force https (option 3)
#Force www / https
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301,NC]
# Directory Index: You can change a default index file from another directory (eg. index.php is inside welcome folder)
# DirectoryIndex welcome index.php
# Access Control: You can Deny / Allow over specific IP address and it's useful when you are doing site updates
Order deny,allow
# Deny all public access
Deny from all
# Allow your IP address so only you can see the site
Allow from xxx.xx.xx.xxx
# Redirect your users to a temporary an error page, welcome page or maintenance page during site update/development with your custom page
ErrorDocument 403 /welcome/comingsoon.php
# Prevent Directory Browsing (Disable/Enable)
# To Disable
Options All -Indexes
# To Enable
# Options All +Indexes
# Create custom error pages and do not forget to create related error html file in source
# And you can extend this like as well:
# ErrorDocument 400 /400.html #400 - Bad Request
# ErrorDocument 401 /401.html #401 - Not Authorized
# ErrorDocument 403 /403.html #403 - Forbidden
# ErrorDocument 404 /404.html #404 - Not Found
# ErrorDocument 500 /500.html #500 - Internal Server Error
# ErrorDocument 502 /502.html #502 - Bad Gateway
# ErrorDocument 504 /504.html #504 - Timeout Error
+============================+
Subscribe to:
Posts (Atom)
Restricted Access to the website with http basic authentication for additional security layer
Restricted Access to the website with http basic authentication for additional security layer ############## #For Nginx Server #########...