I'm having trouble constructing the correct rewrite rule.
Here's what I need the rule to do:
http://www.mydomain.com/this-is-my-page
http://www.mydomain.com/blog/this-is-my-page
Do you want to rewrite or redirect?
If all you want is redirect, then it is really easy:
<rewrite>
<rules>
<rule name="Blog Rule" stopProcessing="true">
<match url="^this-is-my-page$" />
<action type="Redirect" url="/blog/this-is-my-page" />
</rule>
</rules>
</rewrite>
However, if you want to Rewrite, then you will need to make sure that all links, images, styles, scripts, etc, are linked using the site absolute path (/some-link/ rather than some-link/) or otherwise you are going to have a lot of broken links and styles.
You can use URL Rewrite to fix them using Output Rewrite but that is more complicated to get right.
I have a sample that shows how to do some of the output rewrite here: Link
Related
We are trying to add a rewrite rule matching a regular pattern to our wordpress blog using IIS10 (in Windows Server 2019). However the rule is not applying on the first part of the url scheme.
<match url="^blog/(.*)$" />
In this case, the rewrite works for https://example.com/blog/article1 but not for https://example.com/blog/ and is giving us 404 error. Have tried the following with no luck:
Ensure ARR module is installed and Enable proxy is ticked.
Created separate rewrite rule above the existing rule for /blog
<match url="^(blog|blog/)$" />
Created redirect rule for blog to blog/news and then the rewrite rule works. But we would like to preserve the /blog url on the browser.
Here is the rewrite rule that we are trying to crack and would appreciate some suggestions to get it working. Thank you
<rule name="wordpress-rewrite" stopProcessing="true">
<match url="^blog/(.*)$" />
<action type="Rewrite" url="https://blog.example.com/{R:0}" appendQueryString="true" />
</rule>
I'm using IIS 7.5 with URL Rewrite.
I have old legacy urls out on the web that point to urls like this:
http://www.domain.com/games/dog-vs.-cat
http://www.domain.com/games/john.smith-ran-away
I need these urls to be rewritten without the dot:
http://www.domain.com/games/dog-vs-cat
http://www.domain.com/games/johnsmith-ran-away
Here's my rule that is not working.
<rule name="RedirectOldURL" stopProcessing="true">
<match url="^games/([a-zA-Z0-9-]+)$" />
<action type="Redirect" redirectType="Permanent" url="/games/{R:1}" />
</rule>
Is it possible to rewrite the source url without the dot? The dot could appear anywhere in that last piece of url.
Thanks
In action use
<match url="^games/([0-9]+)/([_0-9a-z-]+)" />
and in action block use:
url="games.aspx?id={R:1}&title={R:2}"
I have been struggling with the following for quite some time now:
Default url:
examplesite.com/folder/about.cshtml
Desired url:
examplesite.com/about
Basically I want to accomplish two things:
1 Remove the file extension with realtively compact code.
2 Remove the folder that houses the about page.
I have found some uncommon rules to achieve all the above, but they mostly contain a lot of redundant code that crashes my site when I test it with IIS 8.0.
So I was hoping someone could share a rule that is compact and fits my needs. Or seperate rules with the same outcome.
Every contribution is much appreciated :)
I'm not certain I entirely understand your needs, but here's something that's at least close. It strips out the first folder and file extension (so examplesite.com/folder/about.cshtml becomes examplesite.com/about and examplesite.com/folder/help/about.cshtml becomes examplesite.com/help/about). If you wanted to strip all folders then just remove the ?.
<rule name="Remove Directory and Extension">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Rewrite" url="{R:2}" />
</rule>
Update:
Ok, I think what you want is a combination of two rules then:
<rules>
<rule name="Redirect requests to friendly URLs">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Redirect" url="{R:2}" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^(.*)$" />
<action type="Rewrite" url="folder/{R:0}.cshtml" />
</rule>
</rules>
The first rule makes sure that all requests are to friendly URLs. The second takes the friendly URL and rewrites it to your physical path, where the physical path is folder/[FRIENDLY_PATH].cshtml.
I'm trying to get URL rewriting working but having problems. I have several rules set up with BlogEngine.NET and I want to redirect several pages to a "Coming Soon" page. Despite being able to access a valid page at mydomain.com/page/coming-soon.aspx by typing it directly, if I try to access it via mydomain.com/category.aspx, the rule below does not work - I just get a 404 that '/page/coming-soon.aspx' does not exist.
<rule name="Coming Soon4" stopProcessing="true">
<match url="^category.aspx/?$" />
<action type="Rewrite" url="page/Coming-Soon.aspx" />
</rule>
Don't you mean to have type="Redirect" instead of Rewrite?
I have created a this rule:
<rewrite>
<rules>
<rule name="ImageRedirect" stopProcessing="false">
<match url="^(.*)/(.*)/" />
<action type="Rewrite" url="http://www.lrgimages.com/ImageRewrite.aspx?=img={R:2}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
I keep getting a 404.0 message like the rule is not working or IIS is not picking it up. In the test parttern section for the rule, the pattern tests fine. If I go directly to the http://www.lrgimages.com/ImageRewrite.aspx that page loades, but not when I try: http://www.lrgimages.com/TestImage
any thoughts?
Update: I figured it out. It does not take into acount hte http://www.DomainName.com when rewriting a url. Redirects work this way since htat is what is is really doing. I am used to other rewrite engines not taking into account the http://www.DomainName.com . Thanks all you lead me in the right direction.
I don't think "/TestImage" matches ^(.*)/(.*)/ ...