Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: 1 2 [3] 4

Author Topic: [MOD] Avoiding duplicate content (trailing slash issue)  (Read 16814 times)

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #30 on: August 03, 2008, 11:24:03 AM »

Sorry Armen,

But it is not about (any of) my server(s).I don't need a solution. Didn't you read or understand my post?  ???
And there is no such thing as one good configuration. People have all kinds of hosting, depending on that particular server configuration.



Didn't mean to offend you, Joost.

It's just that I'm now using this solution with 3 different hosting companies and at home. No problems. Different OS'es (Win, FreeBSD, Ubuntu-linux, Bare-Unix - driven servers).

You've done good, Joost. Thank you. And for testing.

Indeed, this solution is not 100% fail-proof because of different server configurations and one day I hope to come up with one really universal solution.
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Sasha

  • Hero Member
  • *****
  • Karma: 28
  • Posts: 947
    • cssanarchy.com
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #31 on: August 04, 2008, 07:11:19 AM »

what i said before "lets make snews1.6 perfect" also welcome back Armen :) and Joost is a great guy :)
Logged
Every morning, I get up and look through the 'Forbes' list of the richest people in America. If I'm not there, I go to work. | If you love your job, you haven't worked a day in your life. snews with ♥

Sven

  • Dev Invitee
  • ULTIMATE member
  • *****
  • Karma: 88
  • Posts: 2069
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #32 on: August 04, 2008, 01:48:29 PM »

Oups !
There's a little problem on keyword search.
The training slash is being applied so search as -http://www.hiseo.fr/tag/wai
gives -http://www.hiseo.fr/tag/wai/
and of course it doesn't work out.
Is there a way to fix that issue in the .htaccess file or in the Mod itself?

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #33 on: August 04, 2008, 02:06:42 PM »

Oups !
There's a little problem on keyword search.
The training slash is being applied so search as -http://www.hiseo.fr/tag/wai
gives -http://www.hiseo.fr/tag/wai/
and of course it doesn't work out.
Is there a way to fix that issue in the .htaccess file or in the Mod itself?

Just add preg_replace() to a string inside keyword search function to get rid of a trailing slash from the search keyword:

Quote
$var = preg_replace("/\/$/","",$var);

where $var is a variable with XSS cleaned search quiery.

Example:

Quote
<?php
$var = "key/";
$var = preg_replace("/\/$/","",$var);
echo $var;
?>

Will output "key" without a trailing slash.

BTW, it's a good idea to get rid of all slashes from any user-specified quiery. Makes it safer. To clear user's input of all slashes, just remove the "$" (dollar) sign from preg_replace.
« Last Edit: August 04, 2008, 02:19:44 PM by Armen »
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Sven

  • Dev Invitee
  • ULTIMATE member
  • *****
  • Karma: 88
  • Posts: 2069
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #34 on: August 04, 2008, 02:52:34 PM »

Okey okey...
I wish good holidays dear ogre. :D

Sven

  • Dev Invitee
  • ULTIMATE member
  • *****
  • Karma: 88
  • Posts: 2069
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #35 on: August 04, 2008, 03:36:02 PM »

didn't find where to paste your piece of code into the function:
Quote
//SEARCH ENGINE ONLY ON KEYWORDS_META
function search_keywords($word) {
echo '<h2>'.l(search_results).'</h2>';
   $word = clean(cleanXSS(dashstrip($word)));
    $query = "SELECT category,seftitle,title,keywords_meta FROM ".db('prefix')."articles WHERE published = 1 AND keywords_meta LIKE '%$word%' ORDER BY date DESC";
    $result = mysql_query($query);
    $numrows = mysql_num_rows($result);
    if (!$numrows) {
      echo '<p>'.l('noresults').' <span class="gras">'.$word.'</span>.</p>';
   }
   else {
            $goodres = 0;   
       while ($r = mysql_fetch_array($result)) {
                $labels = explode(',', $r['keywords_meta']);
                foreach ($labels as $labels){
                    $label = $labels;
                    if($label == $word){
            $date = date(s('date_format'), strtotime($r['date']));
             $finetext = strip_tags($text, '<h1><h2><h3><h4><h5><dl><dt><dd><ul><li><ol><p><hr /><br /><em>');
             $categorySEF = find_cat_sef($r['category']);
           if ( $categorySEF == l('home_sef') )
           {
                      echo '<p><a href="'.db('website').$r['seftitle'].'/">'.$r['title'].'</a></p>';
           }
           else
           {
                      echo '<p><a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/">'.$r['title'].'</a></p>';
           }
                           $goodres = $goodres + 1;   
                    }
                }
            }
            echo '<p>( '.$goodres.' '.l('resultsfound').'  <span class="gras">'.$word.'</span>)</p>';
   }
   echo '<p><br /><a href="'.db('website').'">'.l('backhome').'</a></p>';
   $searched = true;
}
???

Sven

  • Dev Invitee
  • ULTIMATE member
  • *****
  • Karma: 88
  • Posts: 2069
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #36 on: August 05, 2008, 09:34:38 AM »

the ogre is gone on vacations. 8)
Anyone can tell me where this
Code: [Select]
$var = preg_replace("/\/$/","",$var); must be placed?
This a real pain in the a**: my visitors do use the tags cloud machinery. :-\

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #37 on: August 05, 2008, 08:14:18 PM »

Find

Code: [Select]
$word = clean(cleanXSS(dashstrip($word)));
Right after it add:

Code: [Select]
// To get rid of the last trailing slash
$word = preg_replace("/\/$/","",$word);

BTW, I found a hot spot (Wi-Fi) in Ukraine =)
« Last Edit: August 05, 2008, 08:16:01 PM by Armen »
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Sven

  • Dev Invitee
  • ULTIMATE member
  • *****
  • Karma: 88
  • Posts: 2069
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #38 on: August 06, 2008, 08:14:52 AM »

Okey Mr Ogre
it works really fine
Thanks a lot.
BTW, I found a hot spot (Wi-Fi) in Ukraine =)
Do you mind to receive a karma in Ukraine? ;D
« Last Edit: August 06, 2008, 09:05:22 AM by Sven »
Logged

Rui Mendes

  • Development,Testing, Support
  • sNews Dude
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1039
  • sNews1.7
    • Comunidade Portuguesa
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #39 on: August 08, 2008, 02:00:45 AM »

Hello my friends.

I tried your code in localhost, but not works.  :(

I fix your code.
Quote
<IfModule mod_php4.c>
    php_value session.use_trans_sid 0
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
RewriteEngine On
#RewriteBase /sNews16
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?category=$1 [L]
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1/ [R=301,L]


Now this code works fine with me. Can you try ?
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Joost

  • Guest
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #40 on: August 08, 2008, 02:07:03 AM »

Rui, which code did you try?
Logged

Rui Mendes

  • Development,Testing, Support
  • sNews Dude
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1039
  • sNews1.7
    • Comunidade Portuguesa
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #41 on: August 08, 2008, 02:20:41 AM »

Hello my friend, how are you?

I tried all code (from you, Armed, Fun, Sven) from this post, but not redirect well on localhost (with xampp in windows).

I use your code, just change your first quote
Quote
RewriteRule ^(.+)/$ $1/ [R=301,L]

and add this 2 lines too
Quote
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Joost

  • Guest
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #42 on: August 08, 2008, 02:36:50 AM »

Hello Rui,

Works nice, except for one flaw:
- sNews in directory, for instance localhost/snews16/
- Nonexisting localhost/snews1 leads to 500 (internal server error).


Logged

johnflower

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
  • I'm a poet and I didn't know it.
    • Silly Poetry
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #43 on: February 14, 2011, 09:42:38 PM »

thanks a mil for this! searched for very long for a redirect for index.php, and got the trailing slash fix to boot!

Appreciated!

johnflower

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
  • I'm a poet and I didn't know it.
    • Silly Poetry
Re: [MOD] Avoiding duplicate content (trailing slash issue)
« Reply #44 on: February 14, 2011, 09:52:51 PM »

oops, i spoke too soon.

um, i can't access some of the pages and categories on my site. can someone perhaps help out on this? i have the following in my htaccess:

Code: [Select]
<IfModule mod_php4.c>
    php_value session.use_trans_sid 0
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
RewriteEngine On
#RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://%{HTTP_HOST}/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&title=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/ index.php?category=$1&title=$2&commentspage=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_-]+)/([0-9]+)/ index.php?category=$1&nbsp;articlespage=$2 [L]
RewriteCond %{HTTP_HOST} ^papertrading\.co.za [nc]
RewriteRule (.*) http://www.papertrading.co.za/$1 [r=301,nc,L]

Redirect permanent /rss-articles http://feeds.feedburner.com/PaperTrading
Redirect permanent /rss-comments http://feeds.feedburner.com/PaperTrading
Redirect permanent /rss-pages http://feeds.feedburner.com/PaperTrading

site, as can be seen in the code, is www.papertrading.co.za. clicking on archive, contact or any category takes me to an error page.

UPDATE: it seems to be breaking my site completely. the layout is falling apart and images aren't displaying correctly, or not at all.
« Last Edit: February 14, 2011, 09:56:37 PM by johnflower »
Logged
Pages: 1 2 [3] 4