Hi guys.. First post here!! I want use mod_rewrite module of apache to block access to .php files. The only .php file witch the visitors can execute is hosted to http://www.blabla.com/php/index.php Well first of all i want to make this my index file so: DirectoryIndex php/index.php Code (markup): The next i want to do is to make a 404 error page DirectoryIndex php/index.php ErrorDocument 404 php/error.php Code (markup): Well now, i want visitors can access php/index.php only from http://www.blabla.com/ but not from http://www.blabla.com/php/index.php, so Options +FollowSymLinks RewriteEngine On DirectoryIndex php/index.php ErrorDocument 404 php/error.php #see if the request is to the file is from visitor RewriteCond %{REMOTE_ADDR} !127\.0\.0\.1 #if it's from visitor do the following rule RewriteRule php/index\.php e404 Code (markup): I have install xampp to my computer and when i type http://localhost/ i see php/index.php and when i type http://192.168.1.5 i see the error page. (192.168.1.5 is my LAN ip-address ) I want http://192.168.1.5/php/index.php to redirect to http://192.168.1.5/php/error.php and http://192.168.1.5/ to http://192.168.1.5/php/index.php How i can do this?
Options +FollowSymLinks RewriteEngine On DirectoryIndex http://192.168.1.5/php/index.php ErrorDocument 404 php/error.php #see if the request is to the file is from visitor RewriteCond %{REMOTE_ADDR} !127\.0\.0\.1 #if it's from visitor do the following rule RewriteRule php/index\.php e404 Code (markup): and in index.php <?php header("Location: http://192.168.1.5/php/error.php"); ?> PHP: Just a thought, there is probably an easier way of doing it, method is not tested
Maybe you didn't understand what i want to do.. 192.168.1.5 want to be any ip-address (even server-ip) When a visitor clicks www .blabla. com/ he goes to www. blabla. com/php/index.php and when he clicks www .blabla. com/php/index.php he goes to 404 error page (SEO friendly if possible). Thx for the reply man!! I think one more ReWriteCond for REQUEST_URI with the neccessery flags should give me the answer
Sorry, might have skimmed through it a bit quick. I don't know about the .htaccess file but in index.php you could do <?php if ($_SERVER['HTTP_REFERER'] != 'http://www.blabla.com/') { header("Location: error.php"); } ?> PHP: Can't say it would work 100% of the time or if it works But maybe something along those lines would or you could do a window.location with javascript but its not as reliable
Options +FollowSymlinks RewriteEngine on RewriteRule ^/?$ /php/index.php [S=1] RewriteCond %{REQUEST_URI} =/php/index\.php RewriteRule (.*)? /php/error.php [R=404] bla-bla.com to bla-bla.com/php/index.php bla-bla.com/php/index.php to bla-bla.com/php/error.php DOES NOT WORK
If you are going to the site directly (not from another page) there won't be a referrer, therefore undefined