Copy link to clipboard
Copied
I have some URLs with missing &s between variables in the query string. I've fixed the issue that created these bad links, but a bunch of the pages are still in the search engines. I would like to setup a 301 for these so that they end up going to the right place, but none of the things that I've tried works. I've tried all of the options below (both with [0-9]+ and with a specific number) and nothing seems to work. Any suggestions?
I need them to use the [0-9]+ because this is just an example of the issue... there are lots of numbers involved and several different surrounding variables.
<cfif find("[0-9]+reports",cgi.script_name)>
<cfset errorstring = reReplaceNoCase(cgi.query_string, "[0-9]+reports", "&reports")>
<cfoutput>
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#cgi.script_name#?#errorstring#">
<cfabort>
</cfoutput>
</cfif>
<cfif isDefined("[0-9]+reports")>
<cfset errorstring = reReplaceNoCase(cgi.query_string, "[0-9]+reports", "&reports")>
<cfoutput>
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#cgi.script_name#?#errorstring#">
<cfabort>
</cfoutput>
</cfif>
<cfif StructKeyExists(url,'2reports')>
<cfset errorstring = reReplaceNoCase(cgi.query_string, "2reports", "&reports")>
<cfoutput>
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#cgi.script_name#?#errorstring#">
<cfabort>
</cfoutput>
</cfif>
Copy link to clipboard
Copied
I should have writting:
<cfif find("2reports",cgi.query_string)>
<cfset errorstring = reReplaceNoCase(cgi.query_string, "2reports", "&reports")>
<cfoutput>
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#cgi.script_name#?#errorstring#">
<cfabort>
</cfoutput>