I am looking for guidance on an issue trying to change the blog url format to make the categories SEO friendly.
ISSUE
I am trying to have our blog categories URL changed from
https://example.com/blog/-in-category/categories/automotive
to
https://example.com/blog/automotive
Format: [domain]/[blogname]/[category]
I’ve added a custom blog provider and can access the categories with the above format, however, the hierarchical widget still shows the original url.
I did add an outbound rewrite rule that did update the widgets URLs to the correct format, however, it killed the Sitefinity backend (can’t access Pages, Blog Post Content). Scriptresource.axd and Webresource.axd through a 404.
Here is the out bound rule..
<outboundRules>
<rule name="Cat Rewrite Rule">
<match filterByTags="A" pattern="/blog/-in-category/categories/([^$]+)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="\.axd" negate="true" />
</conditions>
<action type="Rewrite" value="/blog/{R:1}" />
</rule>
<preConditions>
<preCondition name="IsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/>
</preCondition>
</preConditions>
</outboundRules>
Errors from backend when trying to access the Pages:
Will a custom blog taxonomy evaluator solve what I am needing to accomplish (which I’m not sure how to do)?
Thanks for your help!
In your case, problem is that you forgot to use precondition. Working example is:
<outboundRules>
<rule name="Cat Rewrite Rule" preCondition="IsHtml">
<match filterByTags="A" pattern="/blog/-in-category/categories/([^$]+)" />
<action type="Rewrite" value="/blog/{R:1}" />
</rule>
<preConditions>
<preCondition name="IsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/>
</preCondition>
</preConditions>
</outboundRules>
P.S. But I am totally agree with #Veselin Vasilev, that cleaner approach is to build custom widget.
You can find source code of built-in widgets here:
Blogs: https://github.com/Sitefinity/feather-widgets/tree/master/Telerik.Sitefinity.Frontend.Blogs
Taxonomies: https://github.com/Sitefinity/feather-widgets/tree/master/Telerik.Sitefinity.Frontend.Taxonomies
I would probably create 2 custom MVC widgets that will handle this scenario:
First would be one that gets all categories and renders the links using the format you want, e.g. BlogCategories widget.
It will just generate a list of categories with links of the likes of "/blog/[category]"
Second widget would be a blog list controller that will have the category as a parameter and will get all blog posts that have that category.
It is a bit of work, but much cleaner than having url rewrite rules I think.
Related
I'm migrating a web application from a Windows (IIS) server to a Linux (Apache) and I have been a few days trying to adapt the application, configs, etc. for Linux/Apache.
Everyting is working except the url friendly I was using with Windows/IIS. And I don't know if this is actually a URL Friendly, a simple redirect or anything else.
This is what I want:
I have a 'app.php' file which is like the main application 'index', and shows different 'pages' depending on the old/ugly url parameters:
https://example.com/app.php?qpage=5&qsubpage=2&action=new
Instead of writting this, I want to use friendly urls like this:
https://example.com/section5/?qsubpage=2&action=new
(Please notice that the second and third parameters 'qsubpage' and 'action' are optional!)
Ok, with IIS and this lines in web.config, it works fine:
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="app.php?qpage={R:1}" />
</rule>
</rules>
</rewrite>
Then, in 'app.php' file I get the current URI and (optional) parameters to show one content or another.
However, I can't reach to get it working with .htaccess.
This is what I have know. It works fine only if there is just one parameter:
If I go to...
https://example.com/section5
...it shows the correct 'page' correctly.
However, if I go to...
https://example.com/section5/?qsubpage=2
or
https://example.com/section5?qsubpage=2
...'qsubpage' is ignored.
If I go to
https://example.com/section5&qsubpage=2
...I get a '404: url not found' error (however it works in Windows)
This is my .htaccess rule:
RewriteEngine On
RewriteRule ^([A-Z-a-z-0-9]+)/?$ simplygest.php?qpage=$1&qsubpage=$2 [L]
I have tried some online mod_rewrite generators and even web.config to .htaccess converters online with no success.
Thanks!
concerning IIS Rewrites.
I want to change this url on my local IIS Instance
http://localhost/MySite/health?key=BczI5MyulpRLxI2kiJmIXwLOm78r3qr8z2gwcsYTGR4=&c
to redirect to this url:
http://localhost/MySite/Health.svc/BczI5MyulpRLxI2kiJmIXwLOm78r3qr8z2gwcsYTGR4=/c
As you can see I don't want the incoming request to use
Health.svc/BczI5MyulpRLxI2kiJmIXwLOm78r3qr8z2gwcsYTGR4=/c
instead to use
health?key=BczI5MyulpRLxI2kiJmIXwLOm78r3qr8z2gwcsYTGR4=&c
The Health.svc is the WCF endpoint name, so I just want /health with the key and filter parameter at the end as shown.
Whatever I put in my web config rewrite it still doesn't work. I am rather confused what bit of the url to put in, as the regex seems to be valid as I can test it in IIS and online regex validators.
<rewrite>
<rules>
<rule name="HealthRewrite" stopProcessing="true" enabled="true">
<match url="MySite\/health\?key=([0-9a-zA-Z=]+)&([a-z])" />
<action type="Rewrite" url="MySite/Health.svc/{R:1}/{R:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
How can I get this to work? I have got the rewrite module installed as can see it in IIS an also can see the dll is registered.
If you want to match the value of the query string in IIS, you need to use {QUERY_STRING}. Here is a demo:
<rewrite>
<rules>
<rule name="Test">
<match url="(Service1)" />
<conditions>
<add input="{QUERY_STRING}" pattern="(key)=(.*)" />
</conditions>
<action type="Rewrite" url="Service1.svc/{C:2}" />
</rule>
</rules>
</rewrite>
This is my web.config.
This URL:
http://localhost/Service1?key=getdata
will redirect to this url:
http://localhost/Service1.svc/GetData
For your last question, why add the MySite prefix? This is because the URL in the Rewrite URL will be used as the redirect URL. Notice that it uses back-references to preserve and rearrange the original URL pieces captured during pattern match. For Rewrite, all prefixes other than localhost must be provided in the Rewrite URL.
I managed to get it working with going to all sorts of sites as its not obvious at all.
They key seemed to put the conditions in and then a {QUERY_STRING} with regex which can then create the {C:1} and {C:2} groups that are pushed into the new rewrite
<rewrite>
<rules>
<rule name="HealthRewrite" stopProcessing="true" enabled="true">
<match url="^health" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="key=([0-9a-zA-Z=]+)&([a-z])" />
</conditions>
<action type="Rewrite" url="/MySite/Health.svc/{C:1}/{C:2}" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
I found it confusing knowing what url to match but with a few simplified tests of just ^health I could see more easily and play around with getting the query string parameters. I had to provide the Rewrite with the /MySite/ prefix which is confusing as the match didn't need that!
I have a ASP.Net Core 2.2 site running as an Azure AppService. As part of the configuration, I have a custom domain with the HTTPS only setting turned on.
I also have the Always on setting turned on on my Appservice.
According to this article
https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/ the Always on setting will be ignored when HTTPS only is on and as a result, my site is always doing a cold start with the first call.
According to the same article, a rule condition can be set in the web.config to not process the Redirect to HTTPS rule if a {warmup_request} is processed.
However, my HTTPS only is set on the custom domain in Azure and not as a rule in the web.config.
I am setting RouteOptions in startup.cs with the following code:
services.Configure<RouteOptions>(options =>
{
options.LowercaseUrls = true;
});
and believe that the rule condition can be done here as well using options.ConstraintMap() but I am unsure as to the syntax or method required to represent the following:
<match url="(.*)" />
<conditions>
<add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
<add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Any help on how to do this will be appreciated
Thanks
From the time this article was written the "https only" has been added as a built-in feature of app services so there is no need to use this rewrite rule anymore.
As to how to minimize the cold start for your application - you may want to consider adding appinit configuration to the web.config as described in App Service Warm-Up Demystified
I am trying to create a rewrite rule to modify a dynamic url.
The reference (nie1000857) at the end of the url is the only dynamic part.
"fulldetails?" needs to be inserted as shown below.
https://www.estateagent.net/property-to-rent/nie1000857
https://www.estateagent.net/**fulldetails?**property-to-rent/nie1000857
So far I have:
<rule name="Add fulldetails?" stopProcessing="true">
<match url="^property-to-rent(.?)" />
<action type="Rewrite" url="fulldetails?property-to-rent/"/>
</rule>
However I can't work out how to extract the dynamic part of the url(nie1000857) and add it to the end of the rewrite url.
Any help/advise would be greatly appreciated and apologies if I have missed something obvious within Microsoft's documentation.
I am a total beginner with creating rewrite rules.
Thank you.
I worked it out.
Thought Id post the answer for anyone trying to achieve the same.
<rule name="Add fulldetails?" stopProcessing="true">
<match url="^property-to-rent/(.+)" />
<action type="Rewrite" url="fulldetails?property-to-rent/{R:1}"/>
</rule>
I have a large amount of files stored in a public Azure blob container, all of which are referenced directly via the HTML in my ASP.NET MVC web application. As an example a path to one of the images in blob storage looks like so:
//<my-storage-account-name>.blob.core.windows.net/public/logo.png
I want to avoid displaying my storage account name in my HTML source code so rather than:
<img src="//<my-storage-account-name>.blob.core.windows.net/public/logo.png"/>
I'd prefer to use this:
<img src="/images/logo.png"/>
I want to avoid setting up an MVC route and using the blob API to load the file into the response stream so thought a web.config solution might be the simplest solution, i.e.
<rule name="Image Redirect" stopProcessing="true">
<match url="^images/(.*)$" ignoreCase="false" />
<action type="Redirect" url="//<my-storage-account-name>.blob.core.windows.net/public/{R:1}" redirectType="Permanent" />
</rule>
QUESTION: Is this the most efficient method given that any page could be loading 30+ images at a time? Or should I just use the public blob URL despite my concerns for performance gains?
I found a Microsoft Hands-on Lab where they recommend the web.config URL rewrite rule option:
Hands on Lab: Maintainable Azure Websites: Managing Change and Scale (July 16, 2014)
(Code Snippet - WebSitesInProduction - Ex4 - UrlRewriteRule)
<system.webServer>
<rewrite>
<rules>
<rule name="redirect-images" stopProcessing="true">
<match url="img/(.*)"/>
<action type="Redirect" url="http://[YOUR-STORAGE-ACCOUNT].blob.core.windows.net/images/{R:1}"></action>
</rule>
</rules>
</rewrite>
"Note: URL rewriting is the process of intercepting an incoming Web request and redirecting the request to a different resource. The URL rewriting rules tells the rewriting engine when a request needs to be redirected, and where should they be redirected. A rewriting rule is composed of two strings: the pattern to look for in the requested URL (usually, using regular expressions), and the string to replace the pattern with, if found. For more information, see URL Rewriting in ASP.NET."