1

Let's say I have the following url: example.com/123456

That url doesn't point to anything - the 123456 is a variable.
With PHP and/or htaccess I wonder if I can:

  1. get the "123456" var
  2. push the var into a meta tag in example.com/index.php
  3. show the original url in the address bar, but display content redirected from example.com/index.php (123456 is ignored, it's just a dummy url).

I'm able to do 1 & 2 with an htaccess rewrite. I have a feeling I can do #3 via javascript, but I wonder if there's a cleaner solution that won't make the address bar change more than needed. Also, I don't want to be hacky - I wonder if this is a legit process?

Here's what I've got so far with .htaccess:

RewriteEngine on
RewriteRule ^([A-Za-z0-9\+/=]+)$ ?t=$1 [NC,R=301,L]

And for the index.php I'm just using:

<meta name="foo" content="https://example.com/<?php echo $_GET['t'] ?>" />

All this works, but in order to get the meta var in php, the url gets changed to example.com/?t=123456. I want to display the dummy url: example.com/123456 but show content from example.com/index.php

The difference between my question and the possible duplicate is that I already am using rewrite. See also the answer to my question, which is nowhere mentioned in the possible duplicate.

calipoop
  • 792
  • 9
  • 31
  • First show us the code you have tried and we can probably help you fix it. – Panama Jack Sep 30 '15 at 22:28
  • 1
    http://httpd.apache.org/docs/2.4/rewrite/remapping.html –  Sep 30 '15 at 22:36
  • 1
    Possible duplicate of [How does url rewrite works?](http://stackoverflow.com/questions/6430858/how-does-url-rewrite-works) – Siguza Sep 30 '15 at 23:10
  • @TinyGiant the solution to my problem was to use [PT] (instead of [R=301]), as shown in that first section of the link you mentioned. If you want to add an official answer, I'll accept it, else I can write a recap answer to my own question. Thanks again! – calipoop Sep 30 '15 at 23:42

1 Answers1

0

What solved my problem was to use the [PT] flag instead of the [R=301] flag. [PT] means "passthrough" and allows you to display a new url without changing the address. The new .htaccess code I'm using:

RewriteEngine on
RewriteRule ^([A-Za-z0-9\+/=]+)$ ?id=$1 [NC,PT,L]

Thanks to Tiny Giant for the helpful link and pointing me in the right direction: http://httpd.apache.org/docs/2.4/rewrite/remapping.html

calipoop
  • 792
  • 9
  • 31