Redirect a folder to another

To redirect a folder to another using .htaccess, create

Or

Or

if new folder is on another domain, you can use https://new-domain.com/OLD_FOLDER

See Redirect

Password Protect Site using htaccess

To password protect a web site or a sub folder using .htaccess, create a .htaccess file in the folder.

Add following content

In this case, i used /etc/apache2/site-logins as AuthUserFile, this will store all user and password. You can change this file path to whatever you need. Make sure it is not accessable from public, so keep it outside of document root of your web site.

Now create a user with command

Redirect site to HTTPS excluding a folder

On a web site, customer need to redirect all pages to HTTPS, but want to keep files in one of the folder on HTTP.

For this, i used following in .htaccess file.

Here any url like yourdomain.extn/auth/ will not get redirected to HTTPS.

See Redirect

apache-http-webserver

Redirect site from www to non-www

It is better to make web site available with one URL. Many sites work with both wwww and non-www (naked domain) urls.

Using www or non-www is personal choice. One advantage of using wwww for URL is when you have lot of sub domains. If you use non-www url, cookies set by the domain will be available to sub domains. This will increase bandwidth usage as cookie need to be sent with every request browser make to web server.

Apache

If you are using Apache web server, you can redirect wwww to non-www url by adding following code in .htaccess file

Redirect non-www to www

Nginx

If you use Nginx, it is better create a server entry for www URL, then set a redirect

If you want to use same server entry for www and non-www, add following code to nginx server entry for the web site.

Redirect www domain to non-www

If you use custom ports, use

Redirect Naked Domain to www

Related Posts

Redirect

htaccess

Disable PHP on a folder

A web site had vlunerability, all allowed hacker to upload backdoor script to “uploads” folder used by the script.

As a quick fix, i disabled PHP execution from “uploads” folder. Doing this for any site is a good dea when if your site is not vlunerable at the moment.

Method 1

To disable PHP execution, create a file with name .htaccess

Add

Method 2

In .htacess, add

See htaccess

htaccess

Redirect domain to SSL (HTTPS)

Or

Redirect a Page to another

You can also use