【问题标题】:wordpress installed in cakephp subfolder on iis window serverwordpress 安装在 iis 窗口服务器上的 cakephp 子文件夹中
【发布时间】:2019-08-09 23:28:03
【问题描述】:

我已经在 microsoft window server 6.2 IIS service 8.5 上安装了 cakephp 2.6 版本 因为我已经在 app 文件夹下的子目录中安装了 wordpress 博客

|_ cakePHP
|     |_ app
|     |_ blog
|     |_ lib
|     |_plugins

cakephp 应用程序中的一切正常运行,wordpress 博客也正常运行 如果我们点击 baseurl/blog/ 就好了 索引页正确显示。

但是当我们更改 wordpress 博客 parmalink 设置中的设置并使 prety url 像 https://www.baseurl.com/blog/hello-world/ 它给出 404 错误,但它使用普通的 url,如 https://www.baseurl.com/blog/?p=1

但我需要漂亮的 parmalink URL,例如 https://www.baseurl.com/blog/hello-world/

我为此搜索了很多文章也找到了很多但没有答案是使用 cakephp 使用窗口服务器 你们都知道.htacces 在 iis 8 上不起作用,所以我在 cakephp 的根文件夹中创建 web.config 文件

|_ cakePHP
|     |_ app
|     |_ blog
|     |_ lib
|     |_plugins
|     |_web.config

根文件夹的代码/上面的web.config是

   <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>

                    <!--# Exclude requests already going to /subfolder to avoid an infinite loop-->
                    <rule name="Imported Rule 1" stopProcessing="true">
                        <match url="^blog.*$" />
                        <action type="None" />
                    </rule>


                    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
                    </rule>

                    <rule name="Exclude direct access to app/webroot/*" stopProcessing="true">
                        <match url="^app/webroot/c$" ignoreCase="false" />
                        <action type="None" />
                    </rule>
                    <rule name="Rewrite routed access to assets(geet_jewellery,img, css, files, js, favicon)" stopProcessing="true">
                        <match url="^(blog|buyanddelight|crm_geet|geet_jewellery1|geet_jewellery|img|css|files|js|favicon.ico)(.*)$" />
                        <action type="Rewrite" url="app/webroot/{R:1}{R:2}" appendQueryString="false" />
                    </rule>
                    <rule name="Rewrite requested file/folder to index.php" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <action type="Rewrite" url="index.php" appendQueryString="true" />
                    </rule>


                </rules>
            </rewrite>
            <httpErrors errorMode="Custom" defaultPath="C:\Inetpub\wwwroot\Indexhome_.htm">
                <error statusCode="403" subStatusCode="4" path="C:\Inetpub\wwwroot\Indexhome_.htm" responseMode="File" />
            </httpErrors>
        </system.webServer>
    </configuration>

以及放在博客目录根文件夹中的web.config,所有wordpress文件都在下面

 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
            <rule name="WordPress: https://www.buyanddelight.com/blog" patternSyntax="Wildcard">
                <match url="*"/>
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                    </conditions>
                <action type="Rewrite" url="index.php"/>
            </rule>


        </rules>

     </rewrite>
  </system.webServer>
</configuration>

我找到了很多答案,但都是不完整的,因为其中一些没有 cakephp,一些没有 wordpress,一些没有 IIS 服务器,其余部分无法正常工作,所以请帮助我解决这个问题。希望得到完整的答案谢谢

您也可以参考下面的链接来澄清我的问题,因为它可以通过 .htaccess 实现,但我无法找到 iis 服务器 web.config 的答案

enter link description here enter link description here

【问题讨论】:

  • 尽量让像 wordpress 这样的安全威胁远离任何适当的框架。也许把它放在一个子域上并重定向到那个。至少那是我会在你的情况下做的事情。但是你可以把整个博客文件夹放在你的 webroot 文件夹中,从那里开始路径应该会更好,我猜我还没有测试过。

标签: wordpress cakephp iis-8 cakephp-2.6 window-server


【解决方案1】:

最后我找到了下面对我有用的答案是在 iis 服务器上对我有用的代码。在 blog 文件夹下创建一个 web.config 文件并放入以下代码

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="WordPress Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
            <outboundRules>
                <clear />
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

【讨论】:

    【解决方案2】:

    好问题,欢迎来到 SO!在这种情况下,我会将 Wordpress 从您的 CakePHP 库中移出。您的 CakePHP 环境将变得极其脆弱。 Wordpress 有一些安全漏洞,当您将其保存为子文件夹时,这些漏洞也会影响您的 CakePHP 环境。文件包含、SQL 注入、跨站点脚本和恶意软件通常与肮脏的插件和主题一起出现。

    【讨论】:

    • 是的,我也可以将 wordpress 文件夹移动到 webroot 中,但问题仍然相同,我将如何获得像 baseurl.com/blog/hello-world 这样的漂亮 url ......如果他们有任何方式实现这个像 web.config 或等让我知道。
    • 有人找到我的问题的答案
    • 如果您将其移动到您的 webroot,您可以使用 Wordpress 使用的默认 .htaccess (codex.wordpress.org/htaccess)。之后,您可以在 Wordpress 中定义您的 URL 的外观。如果您不将其移动到 webroot,则应排除 .htaccess CakePHP 使用中的子文件夹(例如:stackoverflow.com/questions/2249885/…
    • 正如我已经说过的,我的 cakephp 应用程序在 IIS WINDOW SERVER 上,所以 .htacces 将不起作用.....只有 WEB.CONFIG 可以工作,所以请按照我上面的尝试回答,但 .htaccess 不是影响任何事情
    • 谁能回答一下
    猜你喜欢
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2014-05-01
    • 2022-07-08
    相关资源
    最近更新 更多