我的.htaccess中有这个代码,我需要将此转换为microsoft azure托管,因为它不起作用。
RewriteEngine On RewriteCond %{THE_REQUEST} /index\.php[?/\s] RewriteRule ^index\.php$ /en/ [R=301,L] RewriteCond %{THE_REQUEST} /index_cz\.php[?/\s] RewriteRule ^index_cz\.php$ /cz/ [R=301,L] RewriteRule ^/en/?$ index.php [NC,L] RewriteRule ^cz/?$ index_cz.php [NC,L]
有人可以帮助我吗?谢谢你们
答案 0 :(得分:0)
您需要在适当的部分中使用重写规则创建web.config。
我从http://htaccesstowebconfig.com/
生成了以下内容<rule name="rule 1m" stopProcessing="true">
<match url="^index\.php$" />
<action type="Rewrite" url="//en/" />
</rule>
<rule name="rule 2m" stopProcessing="true">
<match url="^index_cz\.php$" />
<action type="Rewrite" url="//cz/" />
</rule>
<rule name="rule 3m" stopProcessing="true">
<match url="^/en/?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php" />
</rule>
<rule name="rule 4m" stopProcessing="true">
<match url="^cz/?$" ignoreCase="true" />
<action type="Rewrite" url="/index_cz.php" />
</rule>
整个web.config文件看起来与此类似
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rule 1m" stopProcessing="true">
<match url="^index\.php$" />
<action type="Rewrite" url="//en/" />
</rule>
<rule name="rule 2m" stopProcessing="true">
<match url="^index_cz\.php$" />
<action type="Rewrite" url="//cz/" />
</rule>
<rule name="rule 3m" stopProcessing="true">
<match url="^/en/?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php" />
</rule>
<rule name="rule 4m" stopProcessing="true">
<match url="^cz/?$" ignoreCase="true" />
<action type="Rewrite" url="/index_cz.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
答案 1 :(得分:0)
我构建了一个简单的PHP项目来模拟重写规则的情况。
根目录:
“en”等文件夹中index.php
的内容为:
echo "response in en folder <br />";
var_dump($_GET);
我利用@ Joe Raio的答案进行了一些修改:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rule 1m" stopProcessing="true">
<match url="^index\.php$" />
<action type="Rewrite" url="/en/" /> <!--modified remove '/'-->
</rule>
<rule name="rule 2m" stopProcessing="true">
<match url="^index_cz\.php$" />
<action type="Rewrite" url="/cz/" /> <!--modified remove '/'-->
</rule>
<rule name="rule 3m" stopProcessing="true">
<match url="^/en/?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php" />
</rule>
<rule name="rule 4m" stopProcessing="true">
<match url="^/cz/?$" ignoreCase="true" /> <!--modified add '/'-->
<action type="Rewrite" url="/index_cz.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
当我访问http://{web_site_name}.azurewebsites.net/index_cz.php?a=a&b=b
之类的网址时,会在网站上返回:
response in cz folder
array(2) { ["a"]=> string(1) "a" ["b"]=> string(1) "b" }
如有任何疑虑,请随时告诉我。