Difference between revisions of ".htaccess"
(2 intermediate revisions by 2 users not shown) | |||
Line 34: | Line 34: | ||
</pre> | </pre> | ||
+ | ==Create a Wildcard Subdomain Redirect== | ||
+ | Add the following to your .htaccess code: | ||
+ | <pre> | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTP_HOST} !^www\.mydomain\.dk$ [NC] | ||
+ | RewriteCond %{HTTP_HOST} ^(.*)\.mydomain.dk$ [NC] | ||
+ | RewriteRule ^(.*)$ http://mydomain.dk/ [P,L,QSA] | ||
+ | </pre> | ||
+ | |||
+ | ==Create an IP-based Whitelist to a WordPress login page== | ||
+ | Create a file called '.htaccess' in the same directory as the 'wp-login.php' page. Add the following code: | ||
+ | <pre> | ||
+ | Order Allow,Deny | ||
+ | Allow from 111.222.333.444 | ||
+ | </pre> | ||
+ | Replace 111.222.333.444 with your IP (you can find your IP at http://hostek.com/IP. Note that you can add multiple IP addresses like so: | ||
+ | <pre> | ||
+ | Order Allow,Deny | ||
+ | Allow from 111.222.333.444 | ||
+ | Allow from 111.222.333.444 | ||
+ | Allow from 111.222.333.444 | ||
+ | Allow from 111.222.333.444 | ||
+ | </pre> | ||
+ | |||
+ | ==Create a password to access the WordPress login page== | ||
+ | Go to the directory outside of your website's public_html folder and create a file called .htpasswd. Within it, add the following: | ||
+ | <pre> | ||
+ | wp-user:$apr1$6DKxmMhU$liMLjMbLcQ1JmgLZix5l1/ | ||
+ | </pre> | ||
+ | '''Note:''' The above file makes any login prompt that uses it have the username 'wp-user' and the password 'wp-password'. You can create your own login info to enter into the above file by [http://www.htaccesstools.com/htpasswd-generator/ clicking here and generating it.]<br /> | ||
+ | <br />Next, create a file called '.htaccess' in the same directory as the 'wp-login.php' page (usually /public_html). Add the following code: | ||
+ | <pre> | ||
+ | <FilesMatch "wp-login.php"> | ||
+ | AuthType Basic | ||
+ | AuthName "Please Enter the WordPress Access Password:" | ||
+ | AuthUserFile /home/username/.htpasswd | ||
+ | Require valid-user | ||
+ | </FilesMatch> | ||
+ | </pre> | ||
+ | The above info will now cause any request to the WordPress login page refer to the password file we just created. Replace 'username' with your cPanel username, usually found on the left side of your cPanel control panel home page. | ||
[[Category:Linux]] | [[Category:Linux]] |
Latest revision as of 16:11, 24 May 2017
Contents
- 1 Can I use a .htaccess file to password protect a directory?
- 2 Enabling Case Insensitive URLs for my Linux site
- 3 Rewriting all URL requests to WWW.
- 4 Rewriting HTTP requests to HTTPS
- 5 Create a Wildcard Subdomain Redirect
- 6 Create an IP-based Whitelist to a WordPress login page
- 7 Create a password to access the WordPress login page
Can I use a .htaccess file to password protect a directory?
Yes, on our LINUX servers you can use a .htaccess file to password protect a directory.
The code to perform this is:
AuthUserFile /usr/local/you/safedir/.htpasswd AuthGroupFile /dev/null AuthName EnterPassword AuthType Basic require user wsabstract
Change the File directory to the directory listed in your File Manager.
Enabling Case Insensitive URLs for my Linux site
Add the following to your .htaccess file:
CheckSpelling on
Rewriting all URL requests to WWW.
Add the following to your .htaccess code:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Rewriting HTTP requests to HTTPS
Add the following to your .htaccess code:
RewriteEngine On RewriteCond %{HTTPS} !^on$ RewriteRule (.*) https://yourdomain/$1 [R,L]
Create a Wildcard Subdomain Redirect
Add the following to your .htaccess code:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.mydomain\.dk$ [NC] RewriteCond %{HTTP_HOST} ^(.*)\.mydomain.dk$ [NC] RewriteRule ^(.*)$ http://mydomain.dk/ [P,L,QSA]
Create an IP-based Whitelist to a WordPress login page
Create a file called '.htaccess' in the same directory as the 'wp-login.php' page. Add the following code:
Order Allow,Deny Allow from 111.222.333.444
Replace 111.222.333.444 with your IP (you can find your IP at http://hostek.com/IP. Note that you can add multiple IP addresses like so:
Order Allow,Deny Allow from 111.222.333.444 Allow from 111.222.333.444 Allow from 111.222.333.444 Allow from 111.222.333.444
Create a password to access the WordPress login page
Go to the directory outside of your website's public_html folder and create a file called .htpasswd. Within it, add the following:
wp-user:$apr1$6DKxmMhU$liMLjMbLcQ1JmgLZix5l1/
Note: The above file makes any login prompt that uses it have the username 'wp-user' and the password 'wp-password'. You can create your own login info to enter into the above file by clicking here and generating it.
Next, create a file called '.htaccess' in the same directory as the 'wp-login.php' page (usually /public_html). Add the following code:
<FilesMatch "wp-login.php"> AuthType Basic AuthName "Please Enter the WordPress Access Password:" AuthUserFile /home/username/.htpasswd Require valid-user </FilesMatch>
The above info will now cause any request to the WordPress login page refer to the password file we just created. Replace 'username' with your cPanel username, usually found on the left side of your cPanel control panel home page.