URL重写并将URL结尾保存为变量

编程入门 行业动态 更新时间:2024-10-22 13:52:58
本文介绍了URL重写并将URL结尾保存为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用URL重写来使artist /(artistname)转到artist / index.php?(artistname)。

I am using url rewriting to have artists/(artistname) go to artists/index.php?(artistname).

我使用此代码执行url重写

I use this code to do the url rewriting

RewriteRule ^artists/(.+)$ artists/index.php?$1

然后我使用此代码获取URL后面的部分?并将其保存为变量

I then use this code to get the part of the URL after the ? and save it as a variable

$pageURL = 'http'; $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } $artist = parse_url($pageURL, PHP_URL_QUERY);

该代码在不使用URL重写时有效,但在使用URL重写时不起作用。我已经通过回应$ artist进行了检查。有人知道出什么问题吗?

That code works when I don't use the URL rewriting, but not when I use it. I have checked it by echoing $artist. Does anyone know what might be going wrong?

推荐答案

您的重写规则需要修复。看来您的规则可能会导致重定向循环,这将导致服务器500错误,但事实并非如此。尝试类似这样的事情。

Your rewrite rule needs to be fixed. It looks like your rule could cause a redirect loop, this should result in a server 500 error, surprised that it doesn't. Try something more like this.

RewriteCond %{REQUEST_URI} !^/artists/index.php.* RewriteRule ^artists/(.+)$ artists/index.php?$1 [L]

条件语句应该从循环中消除规则。另外,将[L]标志添加到规则中,以阻止该规则在此时进一步处理。

The conditional statement should eliminate a the rule from looping. Additionally add the [L] flag to the rule to stop the rule from processing more at that point.

更多推荐

URL重写并将URL结尾保存为变量

本文发布于:2023-05-29 23:10:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/355108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并将   重写   变量   保存为   结尾

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!