Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<VirtualHost *:80>
	ServerName admin.fxmagician.com
	ServerAlias www.admin.fxmagician.com
	DocumentRoot /var/www/admin.fxmagician.com/public/

	<Directory /var/www/admin.fxmagician.com/public>
		Options All -Indexes
		AllowOverride All
		Require all granted
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


##.htaccess##
ErrorDocument 403 /restricted.php
SetEnvIf CF-Connecting-IP "^103\.111\.227\.224$" ALLOWED_IP=1
SetEnvIf CF-Connecting-IP "^146\.70\.102\.166$" ALLOWED_IP=2
Require env ALLOWED_IP

<IfModule dir_module>
	DirectoryIndex admin.php 
	DirectoryIndex restricted.php
</IfModule>



What I have tried:

I want to redirect http://admin.fxmagician.com/restricted.php when the page: http://admin.fxmagician.com restricted.
Posted
Updated 4-Feb-24 1:43am

1 solution

You are almost on the right track. You can modify your '.htaccess' file by adding 'ErrorDocument 403 /redirect.php' -

APACHE
ErrorDocument 403 /redirect.php

SetEnvIf CF-Connecting-IP "^103\.111\.227\.224$" ALLOWED_IP=1
SetEnvIf CF-Connecting-IP "^146\.70\.102\.166$" ALLOWED_IP=2
Require env ALLOWED_IP

<IfModule dir_module>
    DirectoryIndex admin.php 
    DirectoryIndex restricted.php
</IfModule>


Create a new file named 'redirect.php' in the same directory as your '.htaccess' file -

PHP
<?php
// When landing on your restricted page, run...
// redirect.php

//Redirect your user to the unrestricted page...
header("Location: /unrestricted.php");
exit();
?>


This way, when your user tries to access a restricted page and encounters a 403 error, they will be redirected to your unrestricted page defined in your 'redirect.php' script.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900