I have many domains (www.vf1.com, www.vf2.com, www.vf3.com etc) which all point to my main domain (www.vf.com). How do I do a 301 redirect from these other domains to my main domain?
So if someone hits www.vf1.com/news/1234 they should get redirected to www.vf.com/news/1234
I also have domains such as images.vf.com, css.vf.com and js.vf.com that I don't need redirecting
I'm using ColdFusion 8 on IIS (but I don't have access to IIS at the moment)
I tried the below on a URL such as http://www.festivalreviews.co.uk/latest/news/14500 but it gets redirected to http://www.virtualfestivals.com/index.cfm
<cfif cgi.http_host IS 'www.festivalreviews.co.uk'>
<cfset jjURL = 'http://www.virtualfestivals.com' & CGI.PATH_INFO>
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#jjURL#">
</cfif>
Thanks
I agree with Adam, if possible, this would probably be better handled using your web server. Having said that, I have had to do similar things in the past with ColdFusion. When I need to rebuild URLs I typically use different CGI variables than what you tried. See if this works for you.
<cfif CGI.SERVER_NAME IS 'www.festivalreviews.co.uk'>
<cfset jjURL = 'http://www.virtualfestivals.com' & CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ ''>
<cfset jjURL = jjURL & '?' & CGI.QUERY_STRING>
</cfif>
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#jjURL#">
</cfif>
CGI.SERVER_NAME - Server's hostname, DNS alias, or IP address
CGI.SCRIPT_NAME - Virtual path to the script that is executing
CGI.QUERY_STRING - Query information that follows the ? in the URL that referenced this script
You can read more about the CGI variables in the documentation here.
Since ColdFusion 8, I use <cflocation> (because CF8 added the statusCode attribute) for these kinds of redirects.
<cfif CGI.SERVER_NAME EQ 'www.festivalreviews.co.uk'>
<cfset jjURL = 'http://www.virtualfestivals.com' & CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ ''>
<cfset jjURL = jjURL & '?' & CGI.QUERY_STRING>
</cfif>
<cflocation url="#jjURL#" addtoken="no" statuscode="301">
</cfif>
<cflocation> documentation: https://wikidocs.adobe.com/wiki/display/coldfusionen/cflocation
Related
I have set up a URL rewrite which works fine when I manually set or type in the URL. But when I use a link in the page within a <cfoutput> tag for example, the link duplicates the string.
I'm using ColdFusion 2016 with IIS 10
For example the URL is
www.site.com/results.cfm?lang=1&categoryid=2&budegtid=all&typeid=all&propertyid=316
and I want it outputted like
www.site.com/properties/en/all/all/all/316
it works but what seems to be happing when I set the link using...
<cfoutput> using the query...
<cfif getProps.recordcount>
<cfoutput query = "getProps" startrow="#url.start#" maxrows="#perpage#">
View
</cfoutput>
the result in the link on the page outputs as www.site.com/properties/en/all/all/all/316/properties/en/all/all/all/316
I have web/config set up as
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<rewrite>
<rules>
<rule name="Property list URL rewrite">
<match url="^property/([_0-9a-z-]+)/([_0-9a-z-]+)/budget-range-([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="resultsproperty.cfm?lang={R:1}&categoryid={R:2}&budegtid={R:3}&typeid={R:4}&propertyid={R:5}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
The ColdFusion cfquery is as follows...
<cfquery name="getProps" datasource="#session.odbcname#">
SELECT *
FROM properties P
INNER JOIN areas A
ON A.area_id = P.property_areaid
INNER JOIN categories C
ON C.category_id = P.property_propcategoryid
INNER JOIN price R
ON R.price_id = P.property_regularity
INNER JOIN types T
ON T.type_id = P.property_proptypeid
WHERE P.property_status != 'Off Market'
<cfif url.ref is not "all">
AND
(
property_ref like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
OR property_refid like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
OR property_town like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
)
</cfif>
ORDER BY P.property_refid
It seems to be pulling in the actual URL first and then adding on the rewrite.
Any help much appreciated.
You need to start the href with a forward slash to indicate it is from root. The href is resolved/interpretted in the browser. Not starting with a forward slash tells the browser that the url is relative to the current path.
If you are at http://example.com/admin/ and have an href logout for example it will be resolved as http://example.com/admin/logout. However if you have an href /logout it will resolve to 'http://example.com/logout.
As your own answer stated, forcing an absolute path works and can be preferred sometimes but sometimes not. Make sure you understand the underlying issue.
Solved! by pre setting the URL root in the coldfusion application file i.e. <cfset request.root = 'http://www.example.com/'> and then reference the #request.root# var within the link, it uses the link correctly and dose not duplicate the url. So this is a cold fusion issue rather than a URL ReWrite issue.
I use jsf 2.2 & prettyfaces-jsf 2-3.3.3 and have /pages/index.xhtml page.
I try redirect from front page to another like this:
<rewrite match="/" url="http://somesite.net" redirect="301" />
Of course, all the pages are redirected. What is the right way redirect only front page?
The match attribute is a regular expression. So you should try something like this instead:
<rewrite match="^/$" url="http://somesite.net" redirect="301" />
I'm doing a site in coldfusion8/mysql 5.0.88 with the front end in Jquery Mobile. I'm also using the photoswipe.js plugin, which allows images to be zoomed and browsed in a separate view layer.
To setup photoswipeable images, I need to output
<cfoutput>
<a class="swipeMe" rel="external" href="#variables.imageSrc#">
<img src="#variables.imageSrc#" class="adaptImg ui-li-thumb" />
</a>
</cfoutput>
The problem is imageSrc is supplied by users, so I have to grab/validate/resize the image before displaying it AND I need the path of the image for the photoswipe-link.
I have been fiddling with this for a while and came up with the following solution:
// read img from user specs
<cfimage name="myImage" source="#bildpfad##bilddateiname#" action="read" />
<cfif IsImage(myImage) is true>
// resize
<cfscript>
ImageSetAntialiasing(myImage,"on");
variables.breite = 400;
ImageScaleToFit(myImage, variables.breite,"", "highestPerformance");
</cfscript>
// write to xml, so I can get the path
<cfxml variable="imageXml">
<cfimage quality=".5" action="writetobrowser" source="#myImage#" class="adaptImg ui-li-thumb"/
</cfxml>
<cfset variables.imageSrc = imageXml.xmlRoot.xmlAttributes.src>
// output
<cfoutput>
<a class="swipeMe" rel="external" href="#variables.imageSrc#">#imageXml#</a>
</cfoutput>
</cfif>
While this works it pretty much stalls the application and memory seems to leak as well, because I'm loosing more and more memory as I'm running this.
Question:
Is there any obvious problem with the above code causing memory leaks? I imagin the images are being written to some sort of temporary directory (CFFileservelet?) and stay there for a while blocking my memory. If so, what would be alternative approaches to handling this in an image search?
Thanks!
Why not just create a /tmp folder on your server, and write the manipulated images there, like:
<cfset newImageName=CreateUUID()&".jpg">
<cfimage action="write" destination="/tmp/#newImageName#" source="#myImage#">
Then you can use it:
<cfoutput>
<a class="swipeMe" rel="external" href="/tmp/#newImageName#"><img src="/tmp/#newImageName#" class="..."></a>
</cfoutput>
Sample scheduled task to delete temp files:
<cfdirectory action="LIST" directory="#expandpath('tmp/')#" name="tempfiles" filter="*.jpg">
<cfloop query="tempfiles">
<cfif dateadd('h',24,dateLastModified) lt now()>
<cffile action="DELETE" file="#expandpath('tmp/')##name#">
</cfif>
</cfloop>
I'm exporting from ColdFusion 9 to Excel and I want to set the page orientation and scaling so the exported excel document fits to page and prints landscape. How to accomplish this?
Edit with solution:
Thanks for the assistance. The page-orientation setting worked as advertised.
I used the following hack to get it to fit to page width.
This page contains documentation on the various settings that are possible:
http://msdn.microsoft.com/en-us/library/Aa155477%28office.10%29.aspx
<cfheader name="Content-disposition" value="attachment;filename=export.xls">
<cfcontent type="application/application/vnd.ms-excel">
<!---
mso-page-orientation:landscape causes the exported excel spreadsheet to be printed landscape.
Setting Scale=45 causes the printout to fit to page width for me.
Per the documentation, I should be able to set
<x:Print><x:FitWidth>1</x:FitWidth><x:FitHeight>32767</x:FitHeight><x:ValidPrinterInfo/></x:Print>
but it doesn't want to work.
The width and height appear correctly in the Page Setup dialog, but the 'Adjust to' scale size
radio button remains selected instead of the 'Fit to' one page wide by 32767 tall radio button.
--->
<HTML xmlns:x="urn:schemas-microsoft-com:office:excel">
<HEAD>
<STYLE>
<!--table
#page {mso-page-orientation:landscape;}
-->
</STYLE>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
<x:Scale>45</x:Scale>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
</HEAD>
<BODY>
<cfoutput>
<cfloop from = "1" to = "#arrayLen(reportItems)#" index = "i">
<table cellpadding="1" cellspacing="1" bgcolor="dcdcdc" width="100%" border="1">
... table contents ...
</table>
</cfloop>
</cfoutput>
</BODY>
</HTML>
IIRC there is nothing baked in. But you can tap into the underlying workbook and use a little POI magic. (Note, these print settings are applied per sheet)
<!--- get the underlying poi sheet --->
<cfset poiSheet = cfSheetObject.getWorkBook().getSheet("TheSheetName")>
<cfset ps = poiSheet.getPrintSetup()>
<cfset ps.setLandscape(true)>
<!--- fit to one page --->
<cfset ps.setFitHeight(1)>
<cfset ps.setFitWidth(1)>
You can use a trick documented on this page:
How to format an Excel workbook while streaming MIME content
Basically, you output a standard HTML table of data that you would like opened as an Excel spreadsheet. You also have to specify the mime-type for Excel, and for good measure I also like to specify the content-disposition header to prompt for a better download file name.
<cfcontent type="application/msexcel"/>
<cfheader name="content-disposition" value="attachment; filename=myFile.xls">
The key to your specific formatting question, then, is also found in that above link. You need to include a <style> block with the MS Office-specific CSS rule mso-page-orientation:landscape;. From that link:
<style>
<!--table
#page
{mso-header-data:"&CMultiplication Table\000ADate\: &D\000APage &P";
mso-page-orientation:landscape;}
br
{mso-data-placement:same-cell;}
-->
</style>
This should handle the page orientation question. One thing to note - Office 2007 and newer will warn users about differing content types when opening this file. It's simply an annoyance (that can be disabled with a registry update); everything will still work and function as needed.
I don't see any attributes to accomplish this in the cfspreadsheet tag. From adobe site:
<cfspreadsheet
action="write"
filename = "filepath"
format = "csv"
name = "text"
overwrite = "true | false"
password = "password"
query = "queryname"
sheetname = "text"
>
You may have to do that after the export in Excel using print ranges or something similar.
Let CF manage exporting the correct data, let Excel handle the formatting/printing.
I am trying to insert a Yahoo weather widget in a JSF page. The code generated by Yahoo is:
<!-- Yahoo! Weather Badge --><iframe allowtransparency="true" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://weather.yahoo.com/badge/?id=12753136&u=c&t=trans&l=vertical" height="255px" width="186px"></iframe><!-- Yahoo! Weather Badge -->
Notice that the iframe src contains a querystring. When I try to run this, I get this error:
Error Traced[line: 42] The reference to entity "u" must end with the ';' delimiter.
Why is it trying to interpret the querystring characters as an entity? How do I get around this?
You're apparently using XML/XHTML. You need to replace all "plain vanilla" ampersands & by &.