简体   繁体   English

如何在ASP运行的服务器上重定向PHP URL?

[英]How can I redirect a PHP url on an ASP ran server?

The site in question used to run on PHP files but was recently changed completely to ASP. 有问题的网站曾用于运行PHP文件,但最近完全更改为ASP。 One of their links is still being used in advertising campaigns and they want to redirect it to the new page. 他们的一个链接仍在广告活动中使用,他们希望将其重定向到新页面。

old link http://example.com/videos.php new link http://example.com/videos.asp 旧链接http://example.com/videos.php新链接http://example.com/videos.asp

When I create the PHP file and use a header() redirect it doesn't function the way I would expect - instead it tried to download the .php file. 当我创建PHP文件并使用header()重定向时,它不会按照我期望的方式运行 - 而是尝试下载.php文件。

What is the best way to redirect traffic that is coming to this link? 重定向到此链接的流量的最佳方法是什么?

I was thinking .htaccess but would that work? 我在想.htaccess但是那会有用吗?

You could install PHP under IIS (very easy to do) and then create a php page http://example.com/videos.php . 您可以在IIS下安装PHP(非常容易),然后创建一个PHP页面http://example.com/videos.php In this page you can redirect to http://example.com/videos.asp inserting this php code only: 在此页面中,您可以重定向到仅插入此PHP代码的http://example.com/videos.asp

<?php
header("location: http://example.com/videos.asp");
?> 

您可以使用Mod_Rewrite实现该功能,如果您使用的是IIS,则可以使用URL重写

You can simply write a rewrite rule in your web server to rewrite requests to http://example.com/videos.php into http://example.com/videos.asp . 您只需在Web服务器中编写重写规则 ,即可将对 http://example.com/videos.php的请求重写为http://example.com/videos.asp If you use IIS, here is a tutorial about how to create a rewrite rule. 如果您使用IIS, 这里有一个关于如何创建重写规则的教程。

When I create the PHP file and use a header() redirect it doesn't function the way I would expect - instead it tried to download the .php file. 当我创建PHP文件并使用header()重定向时,它不会按照我期望的方式运行 - 而是尝试下载.php文件。

You need to install PHP to get that to work 您需要安装PHP才能使其正常工作

What is the best way to redirect traffic that is coming to this link? 重定向到此链接的流量的最佳方法是什么?

It depends on the server 这取决于服务器

I was thinking .htaccess but would that work? 我在想.htaccess但是那会有用吗?

If the server supports ASP but not PHP then it stands a good chance of being IIS which, as far as I know, does not support .htaccess files. 如果服务器支持ASP但不支持PHP,那么很有可能成为IIS,据我所知,它不支持.htaccess文件。

按照回复中的说明安装PHP,然后告诉IIS将.asp文件解析为php并保留原样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM