Insert rel=nofollow in link if not present

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Insert rel=nofollow in link if not present

Post by gerd »

Hi,
I am struggling with the inserting of rel="nofollow" in all links within a certain text block if the link does not has this string.
Example of the textblock:
<!--menu2-->
...
<!--menu3-->

Insert in all links within the textblock <!--menu2-->(.*)<!--menu3--> after
the two characters
<a
shoulds read now <a rel="nofollow"
if the string rel="nofollow" is not already there. So <a class=" will become <a rel="nofollow" class="

My problem is the detection of the string
rel="nofollow"
in existing links

As a workaround I could just insert rel="nofollow" in all links and delete thereafter the string
rel="nofollow" rel="nofollow" to just rel="nofollow"
but the problem is that there other strings like class="..." target="_..." etc. which appear in some links in different places. Thus, I cannot detect if the string rel="nofollow" is already there. Do you have any idea of the filter?
thanks
gerd
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Insert rel=nofollow in link if not present

Post by DataMystic Support »

Hi Gerd,

Please find a filter attached to do this.

Here is the text structure for reference too:

Code: Select all

|--Perl pattern [<!--menu2-->(.*)<!--menu3-->] with []
|  |  [ ] Match case
|  |  [ ] Whole words only
|  |  [ ] Case sensitive replace
|  |  [ ] Prompt on replace
|  |  [ ] Skip prompt if identical
|  |  [ ] First only
|  |  [ ] Extract matches
|  |  Maximum text buffer size 4096
|  |  [ ] Maximum match (greedy)
|  |  [ ] Allow comments
|  |  [X] '.' matches newline
|  |  [ ] UTF-8 Support
|  |
|  +--Perl pattern [<a [^>]*>] with [$0]
|     |  [ ] Match case
|     |  [ ] Whole words only
|     |  [ ] Case sensitive replace
|     |  [ ] Prompt on replace
|     |  [ ] Skip prompt if identical
|     |  [ ] First only
|     |  [ ] Extract matches
|     |  Maximum text buffer size 4096
|     |  [ ] Maximum match (greedy)
|     |  [ ] Allow comments
|     |  [X] '.' matches newline
|     |  [ ] UTF-8 Support
|     |
|     |--Perl pattern [rel="[^"]*"] with []
|     |     [ ] Match case
|     |     [ ] Whole words only
|     |     [ ] Case sensitive replace
|     |     [ ] Prompt on replace
|     |     [ ] Skip prompt if identical
|     |     [ ] First only
|     |     [ ] Extract matches
|     |     Maximum text buffer size 4096
|     |     [ ] Maximum match (greedy)
|     |     [ ] Allow comments
|     |     [X] '.' matches newline
|     |     [ ] UTF-8 Support
|     |   
|     +--Perl pattern [<a ] with [<a rel="nofollow" ]
|           [ ] Match case
|           [ ] Whole words only
|           [ ] Case sensitive replace
|           [ ] Prompt on replace
|           [ ] Skip prompt if identical
|           [ ] First only
|           [ ] Extract matches
|           Maximum text buffer size 4096
|           [ ] Maximum match (greedy)
|           [ ] Allow comments
|           [X] '.' matches newline
|           [ ] UTF-8 Support
|         
Attachments
html add nofollow to a tags.zip
(1.5 KiB) Downloaded 503 times
gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Re: Insert rel=nofollow in link if not present

Post by gerd »

Thanks Simon,
this a great solution.
gerd
Post Reply