1

I have a php script that redirects external url, this is the script

<?php
 header("Refresh: 5; url={$_GET['url']}"); 
 echo 'You are redirecting to ... page'; 
?>

That redirects with this url

http://my-domain.com/url.php?url=http://www.google.com

I wanted to rewrite this url with .htaccess so i added a code in my .htaccess file, this one

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^url/(.*)$ /url.php?url=$1 [L]

So after adding this code, it should redirect with this url

http://my-domain.com/url/?http://www.google.com

Script is working but it's not redirecting to external url, Just one message is appearing that is You are redirecting to ... page and it's just keep reloading the page at 5 seconds.

So what's the problem? It's with the script or by .htaccess?

0

1 Answer 1

1

The problem is that query string is not part of RewriteRule test uri.

You can use:

RewriteEngine On
Options -MultiViews
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^url/$ /url.php?url=%1 [NC,L]
Sign up to request clarification or add additional context in comments.

2 Comments

still not works giving me "403 forbidden error" :( When script redirects to external domain!
It's a problem in your script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.