how to redirect the user if there are any directory name in the url htaccess

user3599194

hello all i am working on a site where i dont want any user to browse my site directory or to view any image/file inside the directory by just typing the address of the image or file in address bar or by any software help.

i think this is possible my .htaccess rewrite rule can anyone help me please my site directory names are members,images,ads from some where on this site i found this

  RewriteCond %{REQUEST_URI} ^/news/latestnews/(.*)$
  RewriteCond %$1 ^(.*)2012(.*)$
  RewriteRule ^(.*)$ /news/2012 [R=301,L]

which redirects the user to new directory but i dont know how to work with htaccess i can not modify the code

Lepanto

You can add following to top of the htaccess file you already have

Options -Indexes

RewriteEngine on 

RewriteCond %{HTTP_REFERER} !^http://(www\.)?YOURDOMAINNAME.*$ [NC] 
RewriteRule \.(gif|jpg|png)$ http://www.YOURDOMAINNAME.com [L]

Options -Indexes will restrict directory listing

RewriteCond %{HTTP_REFERER} !^http://(www\.)?YOURDOMAINNAME.*$ [NC] checks if the request to a file is from within script or if the request has a referrer from your domain

RewriteRule \.(gif|jpg|png)$ http://www.YOURDOMAINNAME.com [L] will redirect to your home page, if some one tries to access the file directly. You can added file extension to this rule by separating it by pipe | symbol, e.g. gif|jpg|png|doc|pdf

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to redirect a directory to an url in htaccess file

htaccess redirect to directory if URL contains

.htaccess redirect to index.php in any directory

How to .htaccess redirect file name to be url parameters on new site?

How to Redirect Domain to Directory .htaccess

How to redirect url to the url with htaccess

htaccess - redirect directory to file with same name

Subdomain redirect to the sub directory with folder name .htaccess

how to Remove Sub directory name from URL with htaccess?

How can hide directory name from the url using htaccess?

How to hide directory name from URL using .htaccess

htaccess Redirect to URL with no page ID and new directory

Redirect to another directory if url match pattern htaccess

Redirect a directory in a forwarded domain to another url with htaccess

How to redirect a specific URL with .htaccess

Htaccess how to not redirect to root if in specific directory

How to ignore subfolders and redirect to the root directory with .htaccess

How to redirect URL into a new URL using .htaccess?

htaccess - how to redirect url with params to base url

How to redirect a URL and then rewrite it to same url with htaccess?

Use .htaccess to redirect to directory URL but show the URL as if in root

.htaccess redirect all urls containing a specific directory name

Htaccess redirect [F] that matches both a directory name and a variable

How to redirect with .htaccess when files are going name/?

How to redirect to another subdirectory with same name with .htaccess

How to redirect specific subdirectory name in htaccess

How to hide .htaccess redirect from user

How to redirect an URL with many parameters to a subfolder name created from the first parameter, with .htaccess?

How to redirect user to current url