1

I'm trying to use GET to capture member IDs in a URL without using the ?name=variable. For instance, instead of using mydomain.com/folder?id=1234 I would like to use mydomain.com/folder/1234 and pick up the id "1234" in the code so I can pass it to another URL.

This page simply redirects by using: <iframe src="http://redirect_domain.com/folder/index.php" />

I have no control over the server I'm redirecting to, but need the variable passed to it. I can append the redirect URL with ?id=1234 ie <iframe src="http://redirect_domain.com/folder/index.php?id=1234" />

Their code will pick up the id by using <?php echo $_GET["id"]; ?>

Thanks for your help.

6
  • Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. Commented Oct 30, 2013 at 16:09
  • What you're looking for is called a rewrite rule. You can use rewrite rules in conjunction with a redirect or proxy. Commented Oct 30, 2013 at 16:09
  • @FreshPrinceOfSO This question is very specific, and he can't have code to do anything with it if he doesn't know at all how to begin. Commented Oct 30, 2013 at 16:09
  • @Brad Then OP is lacking a basic understanding of the problem being solved; which is off-topic. Commented Oct 30, 2013 at 16:10
  • I think you are asking for the rewrite that would take as its input mydomain.com/folder/1234, and redirects it to mydomain.com/folder?id=1234 - did I understand correctly? Commented Oct 30, 2013 at 16:15

3 Answers 3

1

You'll want to use .htaccess for this. Create a file called .htaccess and put it in the same folder mydomain.com is referencing. Put something like the following in there

RewriteEngine On
RewriteRule ^folder/(.*)$ folder?id=$1 [L]

Note: mod_rewrite must be enabled on apache, but it usually is.

Update: I've updated the .htaccess to reflect a local URL since you've made your desired functionality more clear. Using this .htaccess in conjunction with <iframe src="http://redirect_domain.com/folder/index.php?id=<?=$_GET['id']?>" /> should do the trick.

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

9 Comments

I think there's one too many folder/ in your string... but otherwise this looks a lot like the answer I was about to write. Thanks for saving me the trouble.
I included 2x /folder because that's what OP mentioned.
RewriteRule ^folder/(.*)$ redirect_domain.com/folder/index.php?id=$1 [L] should be the correct formulation based on the updated question.
Well, the question changed, so now .htaccess is not the solution
@user1322707 - turn on logging of the Apache server to tell you exactly what the rewrite engine is doing; see httpd.apache.org/docs/current/mod/core.html#loglevel . Once you know what your rule is doing (vs what you thought it's doing) it will be easy.
|
0

Create a .htaccess file and use something like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Comments

0

I feel the need to write my own answer down. The following two lines in your .htaccess should do exactly what you are asking for:

RewriteEngine On
RewriteRule ^folder/(.*)$ redirect_domain.com/folder/index.php?id=$1 [L] 

According to the rewrite rule test site http://martinmelin.se/rewrite-rule-tester/ , when I use an input of folder/1234, it is redirected to redirect_domain.com/folder/index.php?id=1234 which is exactly what you asked for. There is no need for the <iframe... or any actual files in the /folder/ other than the .htaccess ...

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.