Search code examples
wordpresscakephpiis-8cakephp-2.6

wordpress installed in cakephp subfolder on iis window server


i have installed cakephp 2.6 version on microsoft window server 6.2 IIS service 8.5 in that i have installed wordpress blog in sub directory under app folder

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

every thing working correctly in cakephp app also wordpress blog is also working fine if we hit baseurl/blog/ index page appeared correctly.

But when we change the setting in wordpress blog parmalink setting and make prety url like https://www.baseurl.com/blog/hello-world/ it give 404 error but its working with plain url like https://www.baseurl.com/blog/?p=1

but i need the prety parmalink URL like https://www.baseurl.com/blog/hello-world/

i search many article for this also find many but no answer is working with the window server with cakephp as you all are aware .htacces is not work on iis 8 so i create web.config file in root folder of cakephp

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

code of root folder/above web.config is

   <?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>

and the web.config which placed in root folder of blog directory where all wordpress file is below

 <?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>

I found many answers, but all are incomplete because some of them without cakephp some of them without wordpress and someof them without IIS server rest was not working so please help me out from this.

you can also refer below link to clarify my question as it can achieved by .htaccess but I am not able to find answer for IIS server web.config

enter link description here

enter link description here


Solution

  • finally i found the answer which work for me below is the code which work for me on iis server. create a web.config file as well under blog folder and put the below code

    <?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>