wordpress convert webconfig file to htaccess - .htaccess

I am trying to convert this web.config file to a .htaccess but cannot seem to get it correct. Can someone help?
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true"><match url=".*"/><conditions logicalGrouping="MatchAll"><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></conditions><action type="Rewrite" url="index.php"/></rule>
<rule name="WordPress: http://valiantstag.thetribestaging.com" 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>

It looks like the default htaccess/web.config. I you go to options > permalinks, then change the structure, it should force update the .htaccess file whenever the site is running on apache.
When .htaccess doesn't have write permissions, wordpress will ask you to manually update it's contents.

Related

IIS URL rewrite conflict between files and urls

I have the below config for url rewrite in my IIS
<rewrite>
<rules>
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>
The negate directive is there to prevent rewrite for website assets files (css, fonts, etc.) as well as other files from the documents upload/download section.
The issue I just came across is this, one of the urls is like this http://intranet/HR/Training-Basics however when I try to navigate to this url I get 404 because it is being caught by the negate function for file extension ics.
So, I need to be able to access this url, but at the same time I need to be able to download the "ics" files. What is the best way to do it?
You could modify the condition pattern from ics to\.ics, so that the rewrite rule will only rewrite based on file extension instead of specific string segment.
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="\.(css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>

laravel iis web.config apply only to specific routes

I have laravel running on an iis server. There is a default rewrite rule that redirects all unknown urls to index.php
I would like to apply this rule only to urls with a path starting with /api
and additionally to the exact path /login
So
mydomain1.com/assets/logo.png should point to the file or fail if it does not exist
mydomain1.com/api/users
mydomain2.com/api/posts/tags
mydomain1.com/login
should all redirect to index.php
This is the rule without the conditions:
<rule name="Laravel5" stopProcessing="true" enabled="true">
<match url="^" ignoreCase="false"/>
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true"/>
</rule>

IIS URL Rewrite Rules

I have a AngularJS application that utilizes URL Rewriting for linking. My rewrite rule looks like :
<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="^api/(.*)" negate="false" />
</conditions>
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
I found this solution on SO: How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode? and made one modification to allow my API to pass through.
Essentially, I want to redirect all my requests to Default.cshtml EXCEPT calls to my Web API. This works GREAT when I'm I load the app on the base URL like: localhost/myapp. However, if I reload the page on a angular route like: localhost/myapp/dashboard it fails saying:
<Error><Message>No HTTP resource was found that matches the request URI 'http://localhost/myapp/dashboard'.</Message>
<MessageDetail>No type was found that matches the controller named 'dashboard'.</MessageDetail></Error>
I have a work around where I did:
<rewrite>
<rules>
<rule name="Default" stopProcessing="true">
<match url="^(?!lib|api|dist|assets|app/|bower|common|main|signalr|templates|bower_components/).*" />
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
</rewrite>
and it worked fine. Any ideas how I can utilize a cleaner solution above and still accomplish the rewrite?
I need to change the pattern and change {REQUEST_FILE} to {REQUEST_URI} in a couple of places. See my demo here:
<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
</rewrite>

Specific Redirect/Rewrite Rule for web.config

Can someone assist with a redirect rule?
I would like to swap any occurrence of, say, "newjersey", anywhere in the url for "new-jersey".
Any suggestions on how to do this via web.config would be great, as I need to do this right away. TIA!
Got it working via the following:
<rule name="Redirect {1}/newjersey" stopProcessing="true">
<match url="^([^/]+)/newjersey$" ignoreCase="false" />
<conditions trackAllCaptures="true">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="/{R:1}/new-jersey" appendQueryString="false" />

Use urlrewrite to rewrite all requests to root

I want to use web.config and IIS's urlrewrite to rewrite all requests to a certain directory to the root, for example:
From:
mydomain.com/directory/test.php
To:
mydomain.com/test.php
and
From:
mydomain.com/directory/test/test.php
To:
mydomain.com/test/test.php
All parameters, etc should be passed as well. Any idea how to do this using web.config?
I had a requirement for this a while back and found this:
Using Url rewrite to "delete" a folder
There's a small error in the rule which was corrected later by the poster. Here's a copy with the correction should the link dry up (I also made it a bit more generic for your requirements):
<rewrite>
<rules>
<rule name="RemoveDirectory" stopProcessing="true">
<match url="^directory$|^directory/(.*)$" />
<conditions>
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="RewriteToFile">
<match url="^(?!directory/)(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="directory/{R:1}" />
</rule>
</rules>
</rewrite>
Just search and replace directory with your directory name.

Resources