Codeigniter Nginx:将/sitemap.xml重写为/sitemap
我有一个Codeigniter PHP应用程序,并且我已经配置了我的nginx conf来整理一些URL。例如,/index.php/home将重写为/home。 现在,我正在尝试将nginx配置为重写为/sitemap(它构造了xml文件)。这就是我在nginx配置中使用的内容:Codeigniter Nginx:将/sitemap.xml重写为/sitemap,codeigniter,nginx,rewrite,sitemap,Codeigniter,Nginx,Rewrite,Sitemap,我有一个Codeigniter PHP应用程序,并且我已经配置了我的nginx conf来整理一些URL。例如,/index.php/home将重写为/home。 现在,我正在尝试将nginx配置为重写为/sitemap(它构造了xml文件)。这就是我在nginx配置中使用的内容: if ($request_uri ~* ^/sitemap.xml) { rewrite ^/(.*)$ /index.php/sitemap last
if ($request_uri ~* ^/sitemap.xml)
{
rewrite ^/(.*)$ /index.php/sitemap last;
}
出于某种原因,上述规则不起作用,我认为另一条规则可能会相互冲突,但我无法找到解决办法。有人能帮忙吗?(下面是完整的配置文件)
上面的问题是请求URI仍然是/sitemap.xml而不是/sitemap,所以CI无法正确路由它。尝试将“上次”更改为“重定向”:
也考虑使用位置而不是IF(一般避免):
上面的问题是请求URI保留为/sitemap.xml而不是/sitemap,所以CI无法正确路由它,希望这对您有所帮助。尝试将“上次”更改为“重定向”:
也考虑使用位置而不是IF(一般避免):
希望对我的网站有所帮助
# Sitemap.xml
location /sitemap.xml {
alias /venvs/mobilepro/src/mobilepro/static/maps/map.xml;
}
我在我的网站上使用它:
# Sitemap.xml
location /sitemap.xml {
alias /venvs/mobilepro/src/mobilepro/static/maps/map.xml;
}
location = /sitemap.xml
{
rewrite .* /sitemap redirect;
}
# Sitemap.xml
location /sitemap.xml {
alias /venvs/mobilepro/src/mobilepro/static/maps/map.xml;
}