简体   繁体   中英

Remove index.php from CI and Wordpress

I got CI on root folder and Wordpress on sub directory.

After struggling for days I found The issue is: - CI web config is read before WP web.config so CI index.php is successfully removed but NOT WP's.

Accessing website.com calling CI web.config,processed.
Accessing website.com/blog calling CI web.config,processed.

If URL contains no blog , just add an index.php
If URL contains blog , add an index.php after website then add another index.php after blog

Question:
How to do the match URL "IF URL has blog then add another index.php"? Please correct me if I am wrong.

Any help on determining the right webconfig on CI directory would be greatly appreciated!

original URL:

CI

  website.com/index.php/en/user/

WP

  website.com/index.php/blog/index.php/ 



website.com/en/user => codeigniter with the controller User
website.com/blog/hello-world => error 404
website.com/blog/index.php/hello-world => Good result

/apps
/system
/blog
   ../web.config WP =>remove WP index.php
   ../index.php

/web.config CI =>remove CI index.php
/index.php

web config to remove CI index.php

 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>   
   <rewrite>
    <rules>
        <rule name="RuleRemoveIndex" stopProcessing="true">
            <match url="^(.*)$" ignoreCase="false" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
        </rule>

    </rules>
    </rewrite>

    </system.webServer>
 </configuration>

/blog => WP app

web.config on WP dir to remove WP index.php

   <?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <system.webServer>
    <rewrite>
        <rules>
            <rule name="WordPress Rule 1" stopProcessing="true">
                <match url="^index\.php$" ignoreCase="false" />
                <action type="None" />
            </rule>
            <rule name="WordPress Rule 2" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
                <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
            </rule>
            <rule name="WordPress Rule 3" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
                <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
            </rule>
            <rule name="WordPress Rule 4" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                </conditions>
                <action type="None" />
            </rule>
            <rule name="WordPress Rule 5" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                <action type="Rewrite" url="{R:2}" />
            </rule>
            <rule name="WordPress Rule 6" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                <action type="Rewrite" url="{R:2}" />
            </rule>
            <rule name="WordPress Rule 7" stopProcessing="true">
                <match url="." ignoreCase="false" />
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
     </system.webServer>
   </configuration>

UPDATE: web config on root directory if there is blog/ url, rewrite index.php I found out if I deleted web config rules on CI , it doesnot affect WP. it would load website.com/blog/hello-world well

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

                <rule name="wordpress1" patternSyntax="Wildcard">
            <match url="blog[/]?$"/>
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                </conditions>
            <action type="Rewrite" url="index.php/{R:1}"/>
        </rule>
        <rule name="RuleRemoveIndex" stopProcessing="true">
            <match url="^(.*)$" ignoreCase="false" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
        </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

result: 404 error

The solution is using web.config in each directory. When I erased the rules on CI web.config , I found out I can load the WP well.

I use this on CI web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>   
   <rewrite>
    <rules>
        <rule name="RuleRemoveIndex" stopProcessing="true">
            <match url="^(.*)$" ignoreCase="false" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
        </rule>

    </rules>
    </rewrite>

    </system.webServer>
 </configuration>

on WP web.config

   <?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <system.webServer>
    <rewrite>
        <rules>
        <clear/> => add clear to clear the predefined connection strings
            <rule name="WordPress Rule 1" stopProcessing="true">
                <match url="^index\.php$" ignoreCase="false" />
                <action type="None" />
            </rule>
            <rule name="WordPress Rule 2" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
                <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
            </rule>
            <rule name="WordPress Rule 3" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
                <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
            </rule>
            <rule name="WordPress Rule 4" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                </conditions>
                <action type="None" />
            </rule>
            <rule name="WordPress Rule 5" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                <action type="Rewrite" url="{R:2}" />
            </rule>
            <rule name="WordPress Rule 6" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                <action type="Rewrite" url="{R:2}" />
            </rule>
            <rule name="WordPress Rule 7" stopProcessing="true">
                <match url="." ignoreCase="false" />
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
     </system.webServer>
   </configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM