I am trying to make frindly URLs using web.config, and it must rewrite from 1 to (possibly) 2 variables and ignore rewrite if it's a directory name. So I have this URL:
http://www.domain.com/2014/ - Where 2014 is a folder.
http://www.domain.com/2014/publications/ - It's one of the possible URLs
http://www.domain.com/2014/publications/news/ - Another possible URL
While the real URLs would be
http://www.domain.com/2014/
http://www.domain.com/2014/?page=publications
http://www.domain.com/2014/?page=publications&subpage=news
I am trying this web.config but I am getting an error 500.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Friendly 2">
<match url="^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/2014/index.php?page={R:1}&subpage={R:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Am I missing something?
Thanks in advance!
Related
I tried alot to setup my symfony5 on IIS.
I know i need a web.config file. But i dont know which folders i need to place it in and which content it should have.
Is there someone who can help me ?
This is my folder structure:
https://prnt.sc/7JYFDefYmrRM
i tried a web.config file in my wwwroot with this content
<?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="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
When i get the 404 error it said C:\inetpub\wwwroot\bbmolenzicht\public\sfeer
But my files are in the templates folder.
When i run the command php bin/console debug router i get this:
https://prnt.sc/1SXuXo7DCUP4
How can i fix this?
Currently I have a sub-domain https://blog.example.com which I would like to redirect to https://example.com/blog. I'm using Craft CMS running on IIS 7 server.
I tried the code mentioned below but it didn't work:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect blog to new url" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*" />
</conditions>
<action type="Redirect" url="https://example.com/blog/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Update: Adding directory structure
The problem seems to be with the condition you have specified. Your current pattern is .* which will result in a infinite loop. Change the pattern to check for the specific URL as below.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect blog to new url" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*blog\.example\.com.*" />
</conditions>
<action type="Redirect" url="https://example.com/blog/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I tried this and it works for me. Go to http://blog.kaushal.co.in
If you need to troubleshoot URL Rewrite rules, then enable Failed Request tracing for your site. See this for more details: Using Failed Request Tracing to Trace Rewrite Rules
UPDATE
The rewrite rules need to be added to the 117072616095252 present at the site's root "/" and not in a web.config of one of the child folders.
I am looking to use the sub-page link for a website on Azure, for example:
Html file mysubpage.html placed in the wwwroot directory in Azure. I wish to be able to access this page by typing mysite.com/mysubpage into the web browser. However, when I visit this url I get the output "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I understand that I need to do this with a web.config file in the wwwroot directory, but am unsure as to what contents the web.config file needs to contain?
I currently have the following:
<?xml version="1.0" ?> <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
<rule name="Remove html Extension" stopProcessing="true">
<match url="^(.+)\.html$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRewrites" defaultValue="">
<add key="/mysubpage" value="/mysubpage.html" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer> </configuration>
Solved the issue. The following worked which removed the removal of the html extension:
<?xml version="1.0" ?> <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRewrites" defaultValue="">
<add key="/mysubpage" value="/mysubpage.html" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer> </configuration>
I understand that it you want to re-route numerous urls you can do this by adding extra lines with add as follows:
<add key="/mysubpage1" value="/mysubpage1.html" />
<add key="/mysubpage2" value="/mysubpage2.html" />
I have a website mywebsite.com and installed a cms into a sub folder: mywebsite.com/subfolder
I need to now move the cms to parent folder root and I would like url's to be rewritten automatically so when browsing mywebsite.com/subfolder/page1.php you get redirected to mywebsite.com/page1.php
so far the only suggestions I found were redirecting any request to the root folder. In my case I need to rewrite.
Thanks!
I guess the reason why your question is so old and has not been answered is because it is not clear what you are asking for. Using the IIS7 rewrite module is easy, and I will provide a couple of different examples for what I think you are asking (either or).
So if you would like to "rewrite" urls that are in a subfolder but have them appear as if they were in the root, the following would work -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Root_URL_Rewrite" stopProcessing="true">
<match url="^(.*)" />
<action type="Rewrite" url="/subfolder/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If however you would like url's in an old folder (say url's that have been indexed by google) to be redirected (as a permanent 301 redirect) you could use the following example -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect_Root_URL" stopProcessing="true">
<match url="(.*)subfolder(.*)" ignoreCase="true" />
<action type="Redirect" url="{R:2}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Or, if like me you stumpled across this page and are wanting to do a rewrite to a subfolder, and then do a permanent 301 redirect from the old subfolder to the root, you might want something more similar to the following -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect_Root_URL" stopProcessing="true">
<match url="(.*)subfolder(.*)" ignoreCase="true" />
<action type="Redirect" url="{R:2}" redirectType="Permanent" />
</rule>
<rule name="Root_URL_Rewrite" stopProcessing="true">
<match url="^(.*)" />
<conditions>
<add input="{URL}" pattern="^/subfolder/.*" negate="true" />
</conditions>
<action type="Rewrite" url="/subfolder/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I have a widows machine hosted by goddady and I need to create a rule to forward any request with a URL pointing to a non-existing file to be sent to the index.php.
Usually I would do that with the .htaccess but its different in windows hosts.
I found the answer.
I had to put a xml file named 'web.conf' in the root directory, it works in the same way .htaccess does.
I took the rules from ZendFramework Site
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" pattern=""
ignoreCase="false" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
pattern=""
ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This rules will make the server check if the file exsists and if it doesn't then the request is forwarded to index.php