我正在使用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结尾保存为变量
发布评论