1

I am trying to create a simple redirect to another page on login script.

Currently I am rewriting my URLS to the following format using .htaccess:

RewriteRule ^login$ ?i=l [L]
RewriteRule ^login([^/]*)$ ?i=l&=$1

The normal URL is therefore: domain.com/login - although I wish to be able to do the following: domain.com/login&redirect=/account/settings (Where the "redirect" will be the $_GET parameter that I'll be redirecting to after successful login)

My problem is if I access the above URL I get a 404 page not found. What am I doing wrong?

2
  • You confuse & and ? as it looks... An & cannot be part of the url itself. It would have to be "percent encoded". Commented Jun 20, 2015 at 15:25
  • Shouldn't a ? separate the parameters from the path in the URL? Commented Jun 20, 2015 at 15:26

2 Answers 2

1

Try these rules:

RewriteRule ^login/?$ ?i=l [L,QSA]
RewriteRule ^login(&[^/]+)/?$ ?i=l$1 [L,NC]

Though I suggest using:

domain.com/login?redirect=/account/settings

and get rid of 2nd rule altogether.

QSA flag in first rule will add redirect=/account/settings query parameter as $_GET to your php file.

Sign up to request clarification or add additional context in comments.

Comments

0

I use a .htaccess. It's more functional and simple. I do not know if that's what you need but the handling is very simple.

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

Url Example :

domain.com/login/account/settings

The treatment is in the script PHP

$param = $_GET['param'];
echo $param;

Return

login/account/settings

Or then

$param = $_SERVER['REQUEST_URI'];
// (PHP 5 >= 5.2.0)
// $param = filter_input(INPUT_SERVER, 'RESQUEST_URI');
$param = explode('/',$param);
print_r($param);

Return

Array( [0]=> [1]=>login [2]=>account [3]=>settings)

With this method it is possible to accomplish several goals.

Comments

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.