wordpress how to convert htaccess to web.config - wordpress

hello guys i have a wordpress multisite that hosted in iis how can you convert htaccess code to web.cofig?
Example:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
how to add that in my web.config
<?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="^wp-admin$" ignoreCase="false" />
<action type="Redirect" url="wp-admin/" redirectType="Permanent" />
</rule>
<rule name="WordPress Rule 3" 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 4" stopProcessing="true">
<match url="^(wp-(content|admin|includes).*)" ignoreCase="false" />
<action type="Rewrite" url="{R:1}" />
</rule>
<rule name="WordPress Rule 5" stopProcessing="true">
<match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
<action type="Rewrite" url="{R:2}" />
</rule>
<rule name="WordPress Rule 6" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
can you help me with this one guys please.. T_T

Related

Wordpress: Redirect main site to subsite (IIS, Web.config)

I am running the Wordpress multisites on IIS 10 (Windows server). I have 3 sites like that.
https://test.mydomain.com
https://test.mydomain.com/wp-admin
https://test.mydomain.com/subsite1
https://test.mydomain.com/subsite2
<rewrite>
<rules>
<rule name="WordPress Rule 1" enabled="true" 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" enabled="true" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
It works.
I don't really need the main site so I changed the main site to be 2 (https://test.mydomain.com/subsite1)
When the user accesses the website https://test.mydomain.com or https://test.mydomain.com/, I want to redirect to https://test.mydomain.com/subsite1.
In summary, I want to work like that.
https://test.mydomain.com [redirect to ] https://test.mydomain.com/subsite1
https://test.mydomain.com/ [redirect to ] https://test.mydomain.com/subsite1
https://test.mydomain.com/wp-admin or wp-login or anything [it should work as it's. It shouldn't redirect to subsite.]
https://test.mydomain.com/subsite1 [it should work as it is]
https://test.mydomain.com/subsite1/wp-admin [it should work as it is]
https://test.mydomain.com/subsite2/ [it should work as it is]
https://test.mydomain.com/subsite2/wp-admin [it should work as it is]
I have tried this IIS rewrite rules but didn't work.
<rule name="Main To Subsite" enabled="true" stopProcessing="true">
<match url="^https:\/\/test.mydomain.com$" ignoreCase="false" />
<action type="Redirect" url="subsite1/" redirectType="Temporary" logRewrittenUrl="true" />
</rule>
<rule name="Main To Subsite /" enabled="true" stopProcessing="true">
<match url="^http:\/\/test.mydomain.com\/$" ignoreCase="false" />
<action type="Redirect" url="subsite1/" redirectType="Temporary" logRewrittenUrl="true" />
</rule>
I could probably use some regular expressions like lookahead and etc. I am not that familiar with IIS rewrite. I've read up but still not working. Any help would be appreicated.
Edited: I found this https://www.createit.com/blog/multisite-redirect-from-main-site/ but it is done in functions.php. I think that we should be able to do it from IIS rewrite.
Thanks all. I found the answer here https://stackoverflow.com/a/35759141
<rule name="Root Redirect" stopProcessing="true">
<match url="^$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="en/" redirectType="Permanent" />
</rule>

Redirect http to https for multiple wordpress blogs running under IIS

As title stated, I've a Wordpress multisite installation running several blogs under IIS. I need to force redirect from "http" to "https" but only for some of them. Blogs are typically reachable with and without 'www'. Let's say that I have the following blogs:
mickey.it
donald.it
daisy.it
and that only mickey and daisy run are https ready, I need a conditional rewrite condition to add to web.cofig
My web.config file has the typical Wordpress rewrite rules and not much more:
<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>
Where and which new rule to apply (avoiding broke the existing ones)?
Since the url rewrite module uses regex, i'm pretty sure something like this will get you going in the right direction.
<rule name="HTTP to HTTPS" enabled="true" stopProcessing="true">
<match url=".*(mickey.it|donald.it).*" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
Could probably get fancier with the regex here, but it should be valid in the most basic sense.
I played around with it a bit and it seemed to work...

wordpress querystring not reading after rewritten

Using wordpress on IIS 7 in Windows Server 2008. In a header.php file I have an hardcoded link
Link
Which after the page loads the link automatically renders to
Link
The slash is also added in the address bar for the URL if I put only "www.gohere.com?querystring=value". Which would be ok but in my php code I cannot read the value of the querystring.
Code to read the qs
$getThis = get_query_var('querystring');
if(!empty($getThis)){
...DO WORK BUT DOESN'T GET HERE
}
And the rewrite section of web.config as this does some reading/writing. No htaccess as I am on IIS
<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>
Figured out I was using the wrong php code to get value of querystring. Looks like this works fine.
$getThis = $_GET['querystring'];

getting 404 error on admin panel for sub-directory multisite on a sub-domain in wordpress

I am using IIS server and have installed sub-directory multisite on my subdomain.
I have navigated to 'Super Admin -> 'Sites' and used 'Add New' to create a new site. This appears to work, but styling is not there. The homepage is messed up completely but it is added to the list of sites. If I click on Edit or go to Backend, then I get a 404 error message (page not found). What should I do ??
just got the right answer for this. There is a mistake in web.config file.
The correct code is as follows:
<?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>
there is no .htaccess file in the IIS server, I have a web.config file that is generated by wordpress itself at the time on installation of multisite.
web.config generated by wordpress
<?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-]+/)?wp-admin$" ignoreCase="false" />
<action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
</rule>
<rule name="WordPress Rule 3" 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 4" stopProcessing="true">
<match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
<action type="Rewrite" url="{R:1}" />
</rule>
<rule name="WordPress Rule 5" stopProcessing="true">
<match url="^([_0-9a-zA-Z-]+/)?([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
<action type="Rewrite" url="{R:2}" />
</rule>
<rule name="WordPress Rule 6" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

WordPress + Multisite + IIS7, URL Rewrite bug with pagination and 'Older Entries' links causing 404

Using Multisite WordPress (3.3.2) on IIS7 with the standard URL Rewrite rules causes issues with trailing slashes and the pagination links
For example, if you visit a multisite blog with a URL like this: http://mydomain.com/bloga (without trailing slash) the 'Older Entries' link becomes http://mydomain.com/bloga/bloga/page/2/ -- it doubles up the blog slug in the URL causing a 404 error. Additionally any previous page link 1 2 3 4 5 etc have bad URL's as well.
If you visit http://mydomain.com/bloga/ (with trailing slash) the 'Older Entries' link is correctly http://mydomain.com/bloga/page/2/
I have found the issue to be present across multiple servers, with fresh, theme-less and plugin-less installations of WordPress
The standard URL Rewrite rules are as follows:
<?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:1}" />
</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>
Has anyone seen this problem or know of a solution? Thank you
Reported on WP Trac: http://core.trac.wordpress.org/ticket/18034
Noted and hopefully will be fixed in future version

Resources