Showing posts with label .htaccess. Show all posts
Showing posts with label .htaccess. Show all posts

Tuesday, November 15, 2011

How to protect a web page with htaccess with a password

  1. Create a .htpasswd file:
    $ htpasswd -c .htpasswd <username>
    password: 
    
  2. Create or add these lines to .htaccess file:
    • To protect a directory:
      AuthUserFile /full/path/to/.htpasswd
      AuthType Basic
      AuthName "Protected Folder"
      Require valid-user
      
    • To protect a file:
      AuthUserFile /full/path/to/.htpasswd
      AuthType Basic
      AuthName "Protected Page"
      
      <Files "protected_page.html">
        Require valid-user
      </Files>
      

Friday, April 9, 2010

How to Prevent Files from Being Used by Other Website?

Added these lines to your .htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

Thursday, July 3, 2008

Ways to Force HTTPS on HTTP

  1. Add this to your httpd.conf:
    SSLRequire %{HTTP_HOST} eq "www.mydomain.com"
    
  2. Or try this:
    # Turn on Rewriting
    RewriteEngine on 
    
    # Apply this rule If request does not arrive on port 443
    RewriteCond %{SERVER_PORT} !443 
    
    # RegEx to capture request, URL to send it to (tacking on the captured text, stored in $1), Redirect it, and this is last rule.
    RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R,L]
    
  3. Append the following line to httpd.conf:
    Redirect permanent / https://www.mydomain.com/
    
  4. Or try this:
    <NameVirtualHost 122.123.124.1:80>
        ServerName mywebsite.com:80
        ServerAlias http://www.mywebsite.com:80
        ServerAlias 122.123.124.1:80
        Redirect permanent / https://www.mywebsite.com/
    </VirtualHost>
    
  5. Add the following lines to .htaccess:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    
    Make sure you have this line in your httpd.conf file:
    LoadModule rewrite_module modules/mod_rewrite.so
    
  6. Or try this:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R,L]
    
Note: Restart Apache for new configuration to take effect.
$ /etc/init.d/httpd restart