How to disable language embedding in URLs in Sitecore? - url

After setting up a simple Sitecore site, links to pages sometimes contain the current language:
http://example.com/item.aspx
http://example.com/en/item.aspx
I would like to disable this behavior so that all links point to http://example.com/item.aspx without the language as part of the path. How can this be done?

The web.config has a configuration setting for <linkManager> where the languageEmbedding option can be configured:
<linkManager defaultProvider="sitecore">
<providers>
<clear/>
<add name="sitecore" ... languageEmbedding="asNeeded" ... />
</providers>
</linkManager>
The languageEmbedding options are:
asNeeded
always
never
Changing the config to use languageEmbedding="never" will stop the language from showing up in the URL, and likewise languageEmbedding="always" will force the language to always show up in the URL.

You should not use the "asNeeded" option as it might cause multiple urls for the same pages. Use either "never" or "always" which is much more SEO-friendly

Related

What is the effect of omitting "webpages:Enabled" in web.config?

I've seen the question "what is the function of webpages:Enabled in MVC 3 web.config" but the answer merely explains that setting it to "false" disables use of CSHTML pages (although the is no link to the documentation).
I have a project which fails to build unless the line <add key="webpages:Enabled" value="true"> is removed from the web.config file.
Can someone (provide a link to) tell me what the effect of omitting it is? Is the default to allow or deny CSHTML pages?
Thanks
Default value is null which is interpreted as 'true' that would enable *.cshtml pages to be accessible directly.
You may refer to the code base here for reference:
https://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.WebPages.Deployment/WebPagesDeployment.cs

IIS hosting ASP.NET MVC site gives http 404 for urls containing 'web.config'

Requesting a page from IIS (hosts ASP.NET MVC 3 site) with url containing web.config gives 404 error. Urls with app.config have no problem. Local Visual Studio development server has no issues with this type of urls.
1 - What are any other special words other than web.config, being handled this way by IIS?
In request filtering page/hidden segments tab this is the current state:
I guess these are not special words, because IIS handles words like bin, App_code etc without a problem.
Answer: I guess these are the words being handled by IIS this way. So these are the default words I think and this list is configurable (new items can be added to this list).
2 - Are there any quick fixes (like by web.config modification) to handle urls with these special words?
Btw, I am not trying to serve the web.config file. Url format is : www.mysite.com/es/web.config/1
This is part of the IIS configuration under the Request Filtering section:
You can add/remove filters.
However, I do believe this is a really bad idea to remove web.config from it.
http://www.iis.net/configreference/system.webserver/security/requestfiltering
Cause:
As you already shown a snapshot of IIS configuration. These are reserved folder & files in .Net application, so IIS want to preserve those for security.
URLs which contain these strings as returned as 404 response only if these comes in before ? AND exactly between 2 slashes /../ OR at last. Eg: www.example.com/bin/anything.ext OR www.example.com/folder/sub/web.config
IIS match these string anywhere coz, web.config can we at any directory level.
If anything is with those string are there THEN page will be served by IIS. Eg: www.example.com/bin-folder/anthing.ext OR www.example.com/sub/bin.html OR www.example.com/-web.confing/page.aspx are OK.
I recommend to use some other words with these strings OR use at end of URLs with extensions, so that it will not come between two slashes.
Eg: www.example.com/en-web.config/1 OR www.example.com/en/1/web.config.aspx
Even then I have one Tricky Solution:
If you really need these strings exactly without other words in URL THEN I recommend to use URL-ReWrite.. This may not be quick at whole but except 2nd step its quick and handy, coz second step depends on your application.
1- Add this rule in IIS at top level:
regexp match: (/web|^web)\.(config$|config/) //OR as your requirement
re-write to: handler.aspx?url={REQUEST_URI}
<rule name="web-config" stopProcessing="true">
<match url="(/web|^web)\.(config$|config/)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="handler.aspx?url={REQUEST_URI}" appendQueryString="false" />
</rule>
2- In handler.aspx (or in any other language page) check the url GET variable and respond accordingly.Request.QueryString("url")
Do it carefully coz here you are controlling security.
I suggest to include the actual page content to response in handler.aspx or handler.php only rather then redirecting etc.
Before including content verify URL first(by regular expression etc.), and include content hardcoded, do not take any part of URL in to variable and use that variable in response-inclusion-code.
3- After that at last from IIS manager, In a specific website go to request filtering->hidden segment tab and delete the desire string. Eg: web.config. This step can be done by web.config also:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200" />
<hiddenSegments>
<remove segment="web.config" />
</hiddenSegments>
</requestFiltering>
</security>
Now, IIS will serve the page and your handler page will show the output with exact same URL in user browser.

How to have unique URLs for a single dynamic page?

I think my question may be worded incorrectly but heres what I want to do (for SEO purposes).
I have a page that gives a logo and description of a brand e.g. Volvo. I want to use this same page as a template for all manufacturers but just change a few words around to customize it for each manufacturer accordingly. So in the URL I pass it a variable of the manufacturer e.g. "www.example.com/cars.cfm?manufacturer=BMW" and it will show a page that gives information about BMW.
The problem is that for each manufacturer the information is still showing up as the same page "cars.cfm" in the address bar but really I want it to go to a URL like "www.example.com/manufacturers/volvo.cfm" so it appears as a unique page just for that brand. But at the same time I don't want to have to create a seperate CFM (or php/asp) page for each manufacturer.
Is there a clever way to do this at all? I imagine its something to do with URL rewriting but not sure. I am using IIS 7.5.
Creating numerous sub-folders for different car manufacturers is going to be very tedious. My site would also include other types of manufacturers for different products not just cars. I guess URL rewriting would be best but my idea was to have a different 'page' for each manufacturer so the SEO would be improved.
Basically....
www.example.com/manufacturers/audi.cfm
www.example.com/manufacturers/bmw.cfm
www.example.com/manufactueres/volkswagen.cfm
But really I want the data on each of those pages to come from a database which contains unique data for each manufacturer such the logo image and history description.
Here is an example of what I mean:
http://www.fivestarautocentre.co.uk <-- go to bottom of that page and you can see links to various manufacturers
Building on what everyone else said, start by creating your www.example.com/cars.cfm?manufacturer=BMW page and get that working.
Assuming you're on IIS you would then create a web.config file (if it isn't already there) in your root folder.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Cars-Rewrite">
<match url="manufacturer/(\w+)" />
<action type="Rewrite" url="/cars.cfm?manufacturer={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
My regex could be off, but maybe someone else could chime in with the correct regex.
You can certainly handle this with URL rewriting as others have suggested but I think I would take a different approach. Particularly for SEO purposes. The best solution for SEO will be an actual URL for each brand. With that in mind create your site accordingly. Don't use a generic www.example.com/cars.cfm page, use www.example.com/bmw, www.example.com/volvo, etc. You can still have a ColdFusion page under each of those folders that does nothing more than include your generic ColdFusion template from another location (or call a cfc). Since each folder will have it's own unique stub file you can pass the appropriate vehicle manufacturer when the generic ColdFusion template is called. For example, under the www.example.com/bmw page:
<cfset manufacturer = "bmw" />
<cfinclude template="/mytemplates/genericpage.cfm" />
Then your genericpage.cfm uses the assigned variable to display the appropriate text and graphics. You could even get around having to set a particular variable under each folder by parsing the URL and grabbing the manufacturer from it when the template is included and executed. I believe the cgi.script_name variable will contain the path needed to do this.

Invoke ASP.NET MVC Controller When Requesting .html file

I need to add some new life to a legacy application :)
I'd like to call an MVC controller when a "static" HTML page is requested in order to add some markup to the page before returning it to the client.
I tried to follow the approach found in this thread: How to read web.config settings in .html page?
...but even though I have this route defined:
routes.MapRoute(
name: "Topic",
url: "html/{fileName}.html",
defaults: new { controller = "Topic", action = "Index" });
the controller is not being called. I have my web.config defined with:
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="HTML" path="*.html" verb="*"
type="System.Web.UI.PageHandlerFactory"
resourceType="File" preCondition="integratedMode" />
I suspect that I need to call something else besides the PageHandlerFactory or perhaps the issue is something entirely different.
UPDATE: My dev environment is working with integrated pipeline mode, but I need to check if my production environment will support it.
If you do this:
routes.RouteExistingFiles = true;
You should find this works - even without the handler addition. In the controller you can load the HTML directly using the HostingEnvironment.VirtualPathProvider's GetFile method and do something with it - or better still just use a normal MVC view that renders the same content as the static file, just with your additions.
Although be aware that this means any files that are potentially caught by any routes will be pushed into the MVC pipeline. This isn't generally a concern, however, if decent separation of routes and physical paths is used.
I setup the same situation as you and it worked well for me, so you have the key components in place. Some things to keep in mind for the testing and troubleshooting:
Your web.config does need the build provider for the html extension:
<system.web>
<compilation>
<buildProviders>
<add extension=".html"
type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
</system.web>
A copy and paste of your handlers works for me, so that looks good.
And a copy and paste of your MapRoute works for me too, although I used the default Home controller in a clean project. So as a double check just confirm that you have a controller called Topic with an ActionResult method called Index().
And make sure that your url is localhost.com:{port}/html/test.html with the /html/ in the path since your rule asks for that.
Another good test is to change your MapRoute to use aspx instead and test an aspx page and see if that works. That will confirm whether or not it's the IIS mappings or if it's the MVC rules. If it works with aspx then the issue is related to the handler, but if it fails with aspx too then it's something with MVC.
Also confirm that you're using IIS Express and not Cassini. Cassini will not handle that correctly, but IIS Express will. You can confirm by right-clicking on your project and you should see a menu option called "Use Visual Studio Development Studio...". That will only exist if you are currently using IIS Express.

Umbraco Alternative Links doesn't work

Hello I created some page in Umbraco 4.7 CMS,
configure some alternative links to page(section) it looks like.
If I look at
Link to document
/folder/folder2/page1.aspx - workig
Alternative Links
http://site.com/folder/folder2/page1.aspx - workig
http://site.com/en/folder/folder2/page1.aspx - not working
http://site.com/old-folder/folder2/page1.aspx - not working
but in browser just /folder/folder2/page1.aspx show a valid page other links redirect users to 404 page that configured in umbraco config file.
Have you considered using the UrlRewriting module to get this working. You could add a new rule similar to the following:
<add name="page1rewrite"
virtualUrl="^~/en/folder/folder2/page1.aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/folder/folder2/page2.aspx"
ignoreCase="true" />
This could be further improved depending on your exact requirements but you could it you wanted rewrite all urls ~/en/folder/folder2/ to the new location.
An alternative option would be to use the umbracoUrlAlias document type property.

Resources