Redirecting a webpage

Dear Experts,

I need to redirect the url:

http://www.narmi2.com/page1.php

to

http://www.narmi2.com/page1.php?id=1

But each time I try, the browser says that it stops executing the page because of a loop.

How do I redirect this?
LVL 1
narmi2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bansidharCommented:
try

RewriteRule   ^page1.php$    /page1.php?id=1     [L]
ashfoxCommented:
Hello,

Can you not have a php statement where if id="" then:

<html><head>
  <meta http-equiv="Refresh" content="0; url=http://www.narmi2.com/page1.php?id=1">

danirk2Commented:
You can't, the loop is real :
http://www.narmi2.com/page1.php?id=1 will be redirected to http://www.narmi2.com/page1.php?id=1 :)

What you try to acive seems to be that you will get an default parameter "id" for users calling the page without.

You could do this in code (when 'id' is null/empty -> 'id' = "1")
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

under_dogCommented:
Or something like this:
<?php
 
  if (!isset($_GET['id'])) { header('location: http://www.narmi2.com/page1.php?id=1'); }
 
?>

Open in new window

bansidharCommented:
if you want to avoid a redirect you can use


if (!isset($_GET['id'])) {$_GET['id']=1;}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caterham_wwwCommented:
check, if the qs is empty:
RewriteEngine on
RewriteCond %{QUERY_STRING} =""
RewriteRule   ^page1\.php$    /page1.php?id=1     [L]

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.