运行PHP $的.htaccess从C $ C吗?PHP、htaccess

2023-09-02 00:41:40 作者:安稳

说我有需要的URL传递给PHP函数和检索值,以告诉什么新的目标应该是一个重写?有没有办法做到这一点?

Say I have a rewrite that needs to pass the url to a PHP function and retrieve a value in order to tell what the new destination should be? is there a way to do that?

感谢。

更新:

由于至今guys..I我仍然有问题,但我会告诉你我的code:

Thanks so far guys..I am still having trouble but i'll show you my code:

的.htaccess

.htaccess

#I got the file path by echoing DOCUMENT_ROOT and added the rest.
RewriteMap fixurl prg:/var/www/vhosts/mydomain.com/httpsdocs/domain_prototype/code_base/url_handler.php

RewriteEngine On
RewriteRule (.*) ${fixurl:$1} [PT]

PHP:

set_time_limit(0); # forever program!
$keyboard = fopen("php://stdin","r");
while (1) {
        $line = trim(fgets($keyboard));
        print "www.google.comn";  # <-- just test to see if working.
}

不过我得到一个 500内部服务器错误我不知道是否有在我的.htaccess或在我的PHP错误?

However I am getting a 500 Internal Server Error I am not sure if there is an error in my .htaccess or in my PHP?

推荐答案

有一些所谓的RewriteMap指令。

There is something called a RewriteMap.

您可以调用可执行脚本,将返回URL重写来。

You can call an executable script that will return the URL to rewrite to.

检查本文的详细信息和示例(在Perl,但完全适用于任何其他语言):

Check this article for more information and examples (in Perl, but are totally applicable to any other language):

http://www.onlamp.com/酒吧/ A /阿帕奇/ 2005/04/28 / apacheckbk.html

注意事项总结:

必须运行一个读STDIN循环(即办收到的网址后不退出) 必须打印改写到后面有个新行的网址 必须读取和运行Apache作为运行的用户

这是创建地图的方式

RewriteMap fixurl prg:/usr/local/scripts/fixit.php

现在,我们可以在一个重写规则使用它:

And now we can use it in a RewriteRule:

RewriteEngine On
RewriteRule (.*) ${fixurl:$1}

编辑:关于内部服务器错误。最可能的原因是浓汤提到,RewriteMap指令不能在.htaccess中使用,可悲。您可以在.htaccess一个重写规则使用它,但只能在服务器配置或虚拟主机的配置创建它。要确定,检查错误日志。

About the Internal Server Error. The most probable cause is what Gumbo mentions, RewriteMap cannot be used in .htaccess, sadly. You can use it in a RewriteRule in .htaccess, but can only create it in server config or virtual host config. To be certain, check the error log.

所以,唯一的PHP /的.​​htaccess唯一的解决办法是将改写一切,用特定的PHP程序,执行检查和重定向使用Location头。是这样的:

So, the only PHP / .htaccess only solution would be to rewrite everything to a certain PHP program which does the checking and redirects using the Location header. Something like:

RewriteRule (.*) proxy.php?args=$1 [QSA]

然后,在proxy.php

Then, in proxy.php

<?php
      $url = get_proper_destination($QUERY_STRING); #args will have the URI path, 
                                                    #and, via QSA you will have
                                                    #the original query string
      header("Location: $url");
?>