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
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>
Good question and welcome to SO! In this scenario I would move Wordpress away from your CakePHP library. Your CakePHP environment would become extreme vulnerable. Wordpress has some security flaws that will affect your CakePHP environment aswell when you keep it as a subfolder. File inclusion, SQL injection, cross-site scripting and malware often comes together with dirty plugins and themes.
Related
I'm struggling to get the web.config file working for redirects - I'm doing this for the first time. I've been trying plenty of different codes which I found on this site and elsewhere.
We have HTTPS site and I need to redirect HTTP url-s to HTTPS. The website is written in HTML and we have Windows hosting.
I set up a web.config file and added the code below.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Am I missing something here?
Or does it need some time to take effect?
Many thanks in advance!
Kadri
From Scott Hanselman's blog a few years ago, you should try this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I am trying to make works symfony 4 demo application on my environemnt.
I am using IIS with CGI and rewrite module. I can't have access to the home page of the demo, I think my IIS configuration is not well configured. Is there a standard web.config for symfony 4 and IIS? I didn't find anything.
I finally make it works. I convert the rewrite rules of the htaccess to IIS xml.
It looks like below. Hoping it will help others.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I'm using Web Deploy (from VS2013) to publish an ASP.NET MVC site to an IIS 7.5.
I added some URL rewrite rules and custom HTTP response headers through IIS manager.
The problem is everytime I deploy a new version of the site, this extra configuration is deleted.
Is this the expected behaviour or is there something wrong? How can I keep these custom settings on each deploy?
UPDATE
So I understood I need to put these changes in the web.config. I'm trying to put them in the Web.Release.config but it's not being added to the deployed web.config. I guess I'm missing some XDT:Transform rule.
This is what I got in my Web.Release.config (yes, the publishing profile is using this Release config).
<configuration>
<!-- some other stuff -->
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Turn the build action of your web.config to None. That will prevent the file from being deployed each time you publish.
Edit
For inserting entire sections into a web.config from the web.release.config, you need the xdt:Transform="Insert" added like so:
<system.webServer xdt:Transform="Insert">
<rewrite>
<rules>
<rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Ok so I understood I need to add this custom configuration in the web.config using XDT:Transform.
I added this to the Web.Release.config and it worked:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I use a standard web.config file for my projects that are hosted on Windows servers. It takes care of 2 tasks.
It redirects the non-www version of the site to the www version.
It redirects the index file to the root.
See below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="index\.asp(?:l)?" />
<conditions>
<add input="{HTTP_HOST}" pattern="example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/" />
</rule>
<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This works great, except for 1 problem. The index redirect is redirecting all sub-directories to the main, index.
For example:
http://www.example.com/index.asp is redirecting to http://www.example.com like it should.
But, http://www.example.com/about/index.asp is also redirecting to http://www.example.com. I would like it to redirect to http://www.example.com/about/
Any help would be greatly appreciated.
Well, after getting no response here, I posted on various .Net forums and finally got an answer. This rule will fix it:
<rule name="redirect index.asp" stopProcessing="true">
<match url="^(\w*/)?index\.asp" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain\.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}" />
</rule>
I am using the following web.config file to redirect the non-www version of a site to the www version. However, I would also like to have it strip the file name of the index file as well.
For example:
redirecting www.example.com/index.html to www.example.com
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="CanonicalHostNameRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Edit:
Here is my updated config file. But, its causing a 500 error, now.
See CodingGorilla's answer below :)
In order to get rid of the index.html after the redirect, drop the {R:1}. But then you will need to modify that rule so that it triggers only for /index.html requests and create a new rule that triggers on other pages that includes the {R:1} so that requests for example.com/mypage.html will still get redirected properly.
Edit:
Edit #2
And the final answer is!
Based on our chat conversation, I think this is the final rule set:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="index\.htm(?:l)?" />
<conditions>
<add input="{HTTP_HOST}" pattern="example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/" />
</rule>
<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>