Php Phalcon、IIS 7.5和URL重写问题
因此,我在这个链接上遵循Phalcon php教程,但我试图使用IIS 7.5(与apache相反)重新创建流程,并且出现以下添加/错误行为 注意:服务器名称和端口是我通过IIS 7.5在本地创建的,因此如果单击它或复制并粘贴到浏览器地址栏中,它将不会做任何有意义的事情。 场景1:Php Phalcon、IIS 7.5和URL重写问题,php,iis-7.5,phalcon,Php,Iis 7.5,Phalcon,因此,我在这个链接上遵循Phalcon php教程,但我试图使用IIS 7.5(与apache相反)重新创建流程,并且出现以下添加/错误行为 注意:服务器名称和端口是我通过IIS 7.5在本地创建的,因此如果单击它或复制并粘贴到浏览器地址栏中,它将不会做任何有意义的事情。 场景1: 浏览器地址栏输入:http://Phalcon:8181/ 浏览器地址栏结果:http://Phalcon:8181/public/public/public/public/public/...[ad_nauseau
浏览器地址栏输入:
http://Phalcon:8181/
浏览器地址栏结果:
http://Phalcon:8181/public/public/public/public/public/...[ad_nauseaum]../public/
(不是预期的结果。它应该是http://Phalcon:8181/index/index
因为它们在“bootstrap”index.php文件中设置为默认值)浏览器页面结果:预期页面(/public/index.php,然后路由到/public/controllers/index.php,默认情况下使用操作“index”) 场景2:
浏览器地址栏输入:
http://Phalcon:8181/index.php
浏览器地址栏结果:
http://Phalcon:8181/index.php
(不是预期的结果。它应该是http://Phalcon:8181/index/index
因为它们在“bootstrap”index.php文件中设置为默认值)浏览器页面结果:预期页面(/public/index.php,它路由到正确的控制器和操作) 场景3:
浏览器地址栏输入:无
用户操作:点击Phalcon生成的链接并指向“singup/index”
浏览器地址结果:
http://Phalcon:8181/public/signup/index
(不是预期的结果,我预期的是http://Phalcon:8181/signup/index
因为它们都是在Phalcon生成的链接中提供的)
我尝试过弄乱web.configs或引导php,但我所做的每一次更改都会导致IIS出现404-page未找到错误
根据他们的“创建项目->文件结构”部分,我创建了我的站点文件夹结构,如下所示:
tutorial/
app/
controllers/
models/
views/
public/
css/
img/
js/
文件夹“tutorial”是我在IIS 7.5中创建的网站的根目录
在“漂亮的URL”一节中,它描述了如何重定向请求,以便它们能够与Phalcon提供的MVC模式一起工作
所以这个重写模块
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
<location path="public">
</location>
</configuration>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 3" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="index.php?_url=/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?php
try{
// create a router
$router = new \Phalcon\Mvc\Router();
$router->setDefaultController("index");
$router->setDefaultAction("index");
$router->add("/public", array(
"controller" => "index",
"action" => "index"
));
$router->notFound(array(
"controller" => "index",
"action" => "route404"
));
// Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new \Phalcon\DI\FactoryDefault();
// Setup the view component
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views/');
return $view;
});
// Setup a basic URI so that all generated URIs includ the tutorial folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/public/');
return $url;
});
// Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
}
catch (\Phalcon\Exception $e)
{
echo "PhalconException: " , $e->getMessage();
}
?>
重新启动发动机
重写规则^$public/[L]
重写规则(.*)public/$1[L]
将IIS转换为web.config文件“tutorial”文件夹中的格式:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
<location path="public">
</location>
</configuration>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 3" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="index.php?_url=/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?php
try{
// create a router
$router = new \Phalcon\Mvc\Router();
$router->setDefaultController("index");
$router->setDefaultAction("index");
$router->add("/public", array(
"controller" => "index",
"action" => "index"
));
$router->notFound(array(
"controller" => "index",
"action" => "route404"
));
// Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new \Phalcon\DI\FactoryDefault();
// Setup the view component
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views/');
return $view;
});
// Setup a basic URI so that all generated URIs includ the tutorial folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/public/');
return $url;
});
// Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
}
catch (\Phalcon\Exception $e)
{
echo "PhalconException: " , $e->getMessage();
}
?>
和这个重写模块
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
<location path="public">
</location>
</configuration>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 3" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="index.php?_url=/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?php
try{
// create a router
$router = new \Phalcon\Mvc\Router();
$router->setDefaultController("index");
$router->setDefaultAction("index");
$router->add("/public", array(
"controller" => "index",
"action" => "index"
));
$router->notFound(array(
"controller" => "index",
"action" => "route404"
));
// Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new \Phalcon\DI\FactoryDefault();
// Setup the view component
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views/');
return $view;
});
// Setup a basic URI so that all generated URIs includ the tutorial folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/public/');
return $url;
});
// Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
}
catch (\Phalcon\Exception $e)
{
echo "PhalconException: " , $e->getMessage();
}
?>
重新启动发动机
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php?\u url=/$1[QSA,L]
为IIS转换为此格式,并放置在web.config文件的“tutorial/public”文件夹中:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
<location path="public">
</location>
</configuration>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 3" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="index.php?_url=/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?php
try{
// create a router
$router = new \Phalcon\Mvc\Router();
$router->setDefaultController("index");
$router->setDefaultAction("index");
$router->add("/public", array(
"controller" => "index",
"action" => "index"
));
$router->notFound(array(
"controller" => "index",
"action" => "route404"
));
// Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new \Phalcon\DI\FactoryDefault();
// Setup the view component
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views/');
return $view;
});
// Setup a basic URI so that all generated URIs includ the tutorial folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/public/');
return $url;
});
// Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
}
catch (\Phalcon\Exception $e)
{
echo "PhalconException: " , $e->getMessage();
}
?>
至于应该处理路由的PHP引导文件,它的代码如下(它位于“public”文件夹中的index.PHP:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
<location path="public">
</location>
</configuration>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 3" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="index.php?_url=/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?php
try{
// create a router
$router = new \Phalcon\Mvc\Router();
$router->setDefaultController("index");
$router->setDefaultAction("index");
$router->add("/public", array(
"controller" => "index",
"action" => "index"
));
$router->notFound(array(
"controller" => "index",
"action" => "route404"
));
// Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new \Phalcon\DI\FactoryDefault();
// Setup the view component
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views/');
return $view;
});
// Setup a basic URI so that all generated URIs includ the tutorial folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/public/');
return $url;
});
// Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
}
catch (\Phalcon\Exception $e)
{
echo "PhalconException: " , $e->getMessage();
}
?>
关于如何使其无缝工作,您有什么想法吗?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(public/)?([^/]+)$" ignoreCase="false" />
<conditions>
<add input="C:\inetpub\wwwroot\<projectpath>\public\{R:2}" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="public/{R:2}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/index.php?_url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
.由于某些行为既没有记录也没有直观性,因此也涉及了试错
使用与上面类似的web.config
,我能够在IIS 8.5上完成。但是,它最初定义$url->setBaseUri('/')的说明中似乎存在不一致;
,然后显示浏览器访问localhost/tutorial/
的屏幕截图。显然,对于可在localhost/tutorial/
访问的项目,它应该是$url->setBaseUri('/tutorial/');