dqsp60748 2016-02-06 07:32
浏览 211
已采纳

当存在多个参数时,如何仅在干净URL中保留最后一个参数动态

How can I make the last parameter of my url dynamic when I have more then 1 parameters

For instance: http://localhost:8080/series/dynamics/testurl/Shoes/Sports

has 2 parameters namely "shoes" & "Sports". What I would like to achieve is keep Shoes as a static parameter & "Sports" as dynamic parameter which can be changed further to "Running","Tennis" or "Casual". Below is how I have defined the links in php:

<a href="<?php echo 'Shoes'.'/'.$var2; ?>">Sports</a><br/>
<a href="<?php echo 'Shoes'.'/'.$var2; ?>">Running</a><br/>
<a href="<?php echo 'Shoes'.'/'.$var3; ?>">Tennis</a><br/>
<a href="<?php echo 'Shoes'.'/'.$var4; ?>">Casual</a><br/>

While trying to achieve it through above code & htaccess my problem is as soon as an user clicks on Tennis while on "Sports" the url changes to below:

http://localhost:8080/series/dynamics/testurl/Shoes/Shoes/Tennis

Or even if when I click on the sports link for a 2nd time it changes to:

http://localhost:8080/series/dynamics/testurl/Shoes/Shoes/Sports

as a result I am getting 404 Not found error. Hence I am hoping there must be way to keep the 1st parameter staic and only 2nd parameter dynamic. I know its not a very classic way of doing things but I have gon to elementary level in order to be able narrow down on my errors but no luck yet !!!

I checked various sources but nothing was helpful to resolve my problem. Please guide me in the right direction.

.htaccess looks like this:

RewriteEngine On
 RewriteBase /series/dynamics/testurl/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([a-zA-Z]+)/?$ test.php?page=$1 [L,NC,QSA]
 RewriteRule ^([a-zA-Z]+)/([^/]+)/?$ test.php?page=$1&subgroup=$2 [L,NC,QSA] 
  • 写回答

2条回答 默认 最新

  • dpa31905 2016-02-06 16:29
    关注

    Looks it is a case where you need a <base> tag in your HTML to handle relative URLs.

    You can add this just below <head> section of your page's HTML:

    <base href="/series/dynamics/testurl/" />
    

    so that every relative URL is resolved from that base URL and not from the current page's URL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器