Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:46:55+00:00 2026-06-11T05:46:55+00:00

I’m using the following code to update robots.txt depending on whether a specific page

  • 0

I’m using the following code to update robots.txt depending on whether a specific page is flagged as allow or disallow.

<cflock type="exclusive" timeout="5">
    <cfset vRemoveLine = ListContainsNoCase(robots,"Disallow: #sURL#", "#chr(13)##chr(10)#")>
    <cfif vRemoveLine>
        <cfset robots = ListDeleteAt(robots, vRemoveLine, "#chr(13)##chr(10)#")>
    </cfif>
    <cffile action="write"
        file="#sitePath#robots.txt"
        output="#robots#"
        nameconflict="overwrite">
</cflock>

However, it’s not finished and/or could be written better. Specifically, when removing a line, it doesn’t get rid of its associated carriage returns as well, more so if the line was anywhere except right at the bottom.

Screenshots:

1) Before removing line

enter image description here

2) After removing line

enter image description here

Note also the additional blank line at the bottom. I need to lose all these blank lines, in addition to the removal of a disallow and its line break.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:46:57+00:00Added an answer on June 11, 2026 at 5:46 am

    Actually, paying more attention to your code, you can simply do…

    <cfset robots = robots.replaceAll( "(?m)^Disallow: #ReEscape(sURL)#(?:\r?\n|\z)" , "" ) />
    

    …instead of those List functions.

    This removes the line-breaks for the line you’ve just removed, but doesn’t remove any that exist elsewhere in the file (potentially for splitting up sections and improving readability).

    You can of course still also use trim if you want to ensure there are no blanks at the end of the file.

    By way of explanation, here is the above regex again, in extended/comment form:

    (?x)    ## enable extended/comment mode
            ## (literal whitespace is ignored, hashes start comments, also ignored)
    (?m)    ## enable multiline mode
            ## (meaning  ^ and $ match start/end of each line, as well as of entire input)
    
    ^Disallow:\  ## Match literal text "Disallow: " at start of a line.
                 ## (In comment mode, a \ is needed before the space
                 ##  in standard use this is not required.)
    
    #ReEscape(sURL)#   ## use ReEscape to avoid issues since the URL might
                       ## contain characters that are non-literal in a regex.
    
    (?:     ## non-capturing group to contain alternation between...
    
        \r?\n   ## match optional carriage return followed by a newline.
    |       ## or
        \z      ## match end of input (whether there is a newline there or not)
    )
    

    (To use that in CFML, wrap it in both cfsavecontent and cfoutput, then put the resulting variable inside robot.replaceAll(here,'').)

    If you really want to ensure there aren’t multiple newlines in the file, (irrespective of any changes related to removing disallow lines), the simplest way is:

    <cfset robots = robots.trim().replaceAll('\r','').replaceAll('\n{2,}','\n') />
    

    Which trims both ends, then removes all carriage returns, then replaces all instances of at least two newlines with just a single newline.

    (But in general I would probably recommend the initial more specific expression over blanket removal of multiple newlines.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.