dtncv04228 2015-09-30 22:24
浏览 36
已采纳

是否可以从虚拟URL中提取var,在meta中使用它,但显示原始的虚拟URL?

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.

  • 写回答

1条回答 默认 最新

  • dqnz43863 2015-10-01 02:42
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题