如何从 GET 方法中删除 index.php 和变量
how to rid index.php and variables from GET method
我需要将 www.mysite.pl/?title=title-of-my-site&id=123 更改为 www.mysite.pl/some-text/123/
在我的 web.config:
<rule name="topic" >
<match url="^topic\/([_0-9a-z-A-Z-]+)\/([0-9]+)\/" />
<action type="Rewrite" url="index.php?title={R:1}&id={R:2}" />
</rule>
并将此配置更改为 www.mysite.pl/some-text/123/index.php?title=title-of-my-site&id=123
怎么了?
我找到了解决方案!
问题出在 PHP 代码中,其中有很多重定向,这取决于 url 模式。例如:
if(strpos($_SERVER['REQUEST_URI'], "index.php")===false and $_SERVER['QUERY_STRING']<>"" and strpos($_SERVER['QUERY_STRING'], "topic")===false and strpos($_SERVER["REQUEST_URI"], "pattern1,")===false and strpos($_SERVER["REQUEST_URI"], "pattern2,")===false and strpos($_SERVER['QUERY_STRING'], "error_page")===false) {
header ('HTTP/1.1 301 Moved Permanently');
header("Location: index.php?".$_SERVER['QUERY_STRING']);
die();
}
我需要将 www.mysite.pl/?title=title-of-my-site&id=123 更改为 www.mysite.pl/some-text/123/
在我的 web.config:
<rule name="topic" >
<match url="^topic\/([_0-9a-z-A-Z-]+)\/([0-9]+)\/" />
<action type="Rewrite" url="index.php?title={R:1}&id={R:2}" />
</rule>
并将此配置更改为 www.mysite.pl/some-text/123/index.php?title=title-of-my-site&id=123
怎么了?
我找到了解决方案!
问题出在 PHP 代码中,其中有很多重定向,这取决于 url 模式。例如:
if(strpos($_SERVER['REQUEST_URI'], "index.php")===false and $_SERVER['QUERY_STRING']<>"" and strpos($_SERVER['QUERY_STRING'], "topic")===false and strpos($_SERVER["REQUEST_URI"], "pattern1,")===false and strpos($_SERVER["REQUEST_URI"], "pattern2,")===false and strpos($_SERVER['QUERY_STRING'], "error_page")===false) {
header ('HTTP/1.1 301 Moved Permanently');
header("Location: index.php?".$_SERVER['QUERY_STRING']);
die();
}