Looking for some advise on 301 redirects. Currently moving an existing php based site into Umbraco. I would need to map the old page to the new page. Example URLs are:
This redirected the page, but the url in the browser is contact.php. Would this still have a status of 301, and how could I rewrite the URL. Or should I use the IIS7 rewrite rules engine as suggested. If so could some provide an exampel of how I would perform the rewrites.
Not sure off the top of my head about 301 redirects with Umbraco's URLRewriting, but perhaps the easiest way might be to use the excellent 301 URL Tracker package, which among other things, lets you add custom url mappings.
It's also pretty simple to do in IIS. I typically create a "Rewrite map" with all my URLs and their new targets, then create a single rule to read this map. It's a lot easier to do if you have access to the IIS GUI, but in case you don't here's an output from an example web.config.
I created the 301 URL Tracker which Tim mentioned above and it does exactly what you'd like, but there's one problem; nobody seems to be able to map .php/.cfm for example to umbraco yet...
Thanks for your suggestions. It a shame that the 301 URL Tracker does not map .php and other extensions. I tested the URL Config approach with redirectMode=Permanent'. But the header status gave a reponse of 200, for contact.php. For SEO I would need this to return a status of 301.
So I've decided to use the global.asax for the redirects. Not sure if there are any downside to this approach, but I used it in the past for non Umbraco projects.
protected void Application_BeginRequest(object sender, EventArgs e) { if (HttpContext.Current.Request.Url.ToString().Contains("http://domain.com/contact.php")) { HttpContext.Current.Response.Status = "301 Moved Permanently"; HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace( "http://domain.com/contact.php", "http://domain.com/contact-us.aspx")); }
}
This returns the desired 301 status. For this approach I've created a new global.asax file and deleted the App_global.asax.dll. Remember reading a post, stating thats this does nothing, and so was safe to delete (seems to be OK!!). If possible it would be good to keep this and get the new global.asax to inherit from it. Tried, but the redirects need not work.
Well, the 301 URL Tracker can map, as far as I know, anything, including .php. The only problem is; we're not able to let umbraco handle the .php request, so the 301 URL Tracker is able to kick in...
The IIS Rewrite rules I posted (should) work with PHP and will do 301's, and might be easier to maintain than a code solution. But either way should work :)
I agree with Tom, using the UrlRewrite IIS plugin is better than doing it in-code; - Easily adjustable - More readable/maintainable - Better performance
Using V2.2.2 of the 301 Url Tracker on a V6.1.2 site I can quite happily redirect from whatever.php to a nice new Umbraco page/node without any changes to the UrlReWriter.config file. However, one gotcha I came across in the Url Tracker set up is that it strips the ".php" part of the old url you're trying to set in the form when it saves if you don't have "Forward query string" checked. It appears that Url Tracker considers a file extension to be a query string.
Just thought I'd mention it in case others were head scratching.
Best approach for 301 redirects
Hi,
Looking for some advise on 301 redirects. Currently moving an existing php based site into Umbraco. I would need to map the old page to the new page. Example URLs are:
http://domain.com/contact.php to http://domain.com/contact-us.aspx
http://domain.com/services.php#products to http://domain.com/services/products.aspx
The hosting provider has asked me to use IIS7 rewrite rules engine, which I've not used and so thought I'd use the Umbraco URLRewriting.config.
As a test i used:
This redirected the page, but the url in the browser is contact.php. Would this still have a status of 301, and how could I rewrite the URL. Or should I use the IIS7 rewrite rules engine as suggested. If so could some provide an exampel of how I would perform the rewrites.
Thanks in advance,
Eddie
Hi Eddie,
Not sure off the top of my head about 301 redirects with Umbraco's URLRewriting, but perhaps the easiest way might be to use the excellent 301 URL Tracker package, which among other things, lets you add custom url mappings.
It's also pretty simple to do in IIS. I typically create a "Rewrite map" with all my URLs and their new targets, then create a single rule to read this map. It's a lot easier to do if you have access to the IIS GUI, but in case you don't here's an output from an example web.config.
Hope this helps,
-Tom
Hi Eddie,
I created the 301 URL Tracker which Tim mentioned above and it does exactly what you'd like, but there's one problem; nobody seems to be able to map .php/.cfm for example to umbraco yet...
I'd say, use your current setup and add 'redirectMode=Permanent' as mentioned in this documentation file: http://www.urlrewriting.net/Download.ashx?File=4640f315-27ae-4ab0-8930-6957cfd1f138
Hi Tim and Kipusoep,
Thanks for your suggestions. It a shame that the 301 URL Tracker does not map .php and other extensions. I tested the URL Config approach with redirectMode=Permanent'. But the header status gave a reponse of 200, for contact.php. For SEO I would need this to return a status of 301.
So I've decided to use the global.asax for the redirects. Not sure if there are any downside to this approach, but I used it in the past for non Umbraco projects.
This returns the desired 301 status. For this approach I've created a new global.asax file and deleted the App_global.asax.dll. Remember reading a post, stating thats this does nothing, and so was safe to delete (seems to be OK!!). If possible it would be good to keep this and get the new global.asax to inherit from it. Tried, but the redirects need not work.
Thanks again,
Eddie
Well, the 301 URL Tracker can map, as far as I know, anything, including .php. The only problem is; we're not able to let umbraco handle the .php request, so the 301 URL Tracker is able to kick in...
Hi Eddie,
The IIS Rewrite rules I posted (should) work with PHP and will do 301's, and might be easier to maintain than a code solution. But either way should work :)
-Tom
I agree with Tom, using the UrlRewrite IIS plugin is better than doing it in-code;
- Easily adjustable
- More readable/maintainable
- Better performance
In UrlRewriting.config the following should work
Hi Doug,
Thanks for this. Almost, the page redirects and the url is updated in the browser. But the 404 page is displayed?
Any ideas.
Thanks,
Eddie
Strange.
So if you go direct to '/contact-us.aspx' the page displays fine but if it's the target for the 301 you get a 404 error?
@kipusoep Thanks for 301 URL Tracker package - it's one of the first packages I install on new sites.
I've been investigating the issue of getting it to work with .php/.cfm pages :-
I belive that the umbraco 404 handlers only work with .aspx or extensionless url's (this is hard coded into the umbraco requestModule).
As a workaround you can set-up the UrlRewritter to rewrite .php requests to a .aspx page that does't exist :-
This then enables you to use the custom mapping in the 301 URL Tracker
e.g.
Custom mappings :-
/php/oldpage.aspx
/php/olddir/oldpage.aspx
So /oldpage.php or /olddir/oldpage.php will get 301 redirected to the umbraco page that you've set the custom mapping on.
That's a great suggestion Doug! Thanks!
Hi Kipusoep and Doug,
Installed the 301 URL tracker and have set up the rewrtie using Doug's work around for the php files. Working nicely.
Thanks again,
Eddie
Using V2.2.2 of the 301 Url Tracker on a V6.1.2 site I can quite happily redirect from whatever.php to a nice new Umbraco page/node without any changes to the UrlReWriter.config file. However, one gotcha I came across in the Url Tracker set up is that it strips the ".php" part of the old url you're trying to set in the form when it saves if you don't have "Forward query string" checked. It appears that Url Tracker considers a file extension to be a query string.
Just thought I'd mention it in case others were head scratching.
Cheers,
Craig
@Craig100
It should work with or without "Forward query string". Just tested it and it works for me, so it sounds like a setup issue...
@kipusoep
You're right! Just redeployed the site as 6.1.5 and removed the check on the "Forward Querystring" boxes and they all worked. What can I say?
Thanks,
Craig
is working on a reply...