URL重写并将URL结尾保存为变量 [英] URL Rewriting and save end of URL as variable

查看:74
本文介绍了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结尾保存为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆