Mobile app version of vmapp.org
Login or Join
Shakeerah822

: How to redirect if directory does not exist or should not be seen? I am using Apache and want to modify my .conf file for a website such that: If the request comes from my IP 1.2.3.4,

@Shakeerah822

Posted in: #Apache #ModRewrite

I am using Apache and want to modify my .conf file for a website such that:


If the request comes from my IP 1.2.3.4, just display the URL/page as requested
If the request is not from my IP and the directory does not exist, redirect to root
If the request is not from my IP and the directory is one I don't want to display to anyone (example.com/secret/, example.com/secret2/hidden.html, etc.), redirect to root


What is the best way to do this?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shakeerah822

1 Comments

Sorted by latest first Latest Oldest Best

 

@Turnbaugh106

Best way to do this is not from your .conf file.
Do this:

.htaccess example:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^192.168.1.1 #Replace with IP address you wish to allow
RewriteRule .* www.yourwebsite.com [R=301,L] #Replace webaddress with yours


Make this file in the directories you are trying to keep people out of.

Then make a custom 404 page that redirects to root for the non-existant directories.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme