News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Pretty URLs

Started by SMFHacks.com Team, January 31, 2007, 10:56:43 AM

Previous topic - Next topic

vbgamer45

I don't think this would work if you have windows shared hosting. You would have to ask your host to install.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

anikpand

is there any way i can sort it out

vbgamer45

You would have to ask your host
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

nend

Been really tiding up the code on this with my preferences.
So forth,
I eliminated the need for the mod to have anything DB related.
Removed the admin panel of the mod as it was no longer needed.
Removed allot of redundancy that was there to accommodate administration options.
Edited code in the sources to reflect changes.

My filters file if you see anything worth wild.
<?php
// NEnd's custom Pretty URLs OB rewrite
// Based on Version 1.0 PrettyUrls-Filters.php

if (!defined('SMF'))
die('Hacking attempt...');

// Rewrite the buffer with Pretty URLs!
function pretty_rewrite_buffer($buffer) {
global $boardurl$context;

// Remove the script tags now
$context['pretty']['scriptID'] = 0;
$context['pretty']['scripts'] = array();
$buffer preg_replace_callback('~<script.+?</script>~s''pretty_scripts_remove'$buffer);

// Find all URLs in the buffer
$context['pretty']['search_patterns'][] = '~(<a[^>]+href=|<link[^>]+href=|<form[^>]+?action=|<meta property=\"og:url\" content=|<meta property=\"og:image\" content=|<meta property=\"og:video\" content=)(\"[^\"#]+|\'[^\'#]+)~';
$urls = array();
$context['pretty']['cached_urls'] = array();
foreach ($context['pretty']['search_patterns'] as $pattern) {
preg_match_all($pattern$buffer$matchesPREG_PATTERN_ORDER);
foreach ($matches[2] as $match) {
// Rip out everything that shouldn't be cached
$match preg_replace(array('~^[\"\']|PHPSESSID=[^;]+|(se)?sc=[^;]+|' $context['session_var'] . '=[^;]+~''~\"~''~;+|=;~''~\?;~''~\?$|;$|=$~'), array('''%22'';''?'''), $match);
// Absolutise relative URLs
if (!preg_match('~^[a-zA-Z]+:|^#|@~'$match) && SMF != 'SSI')
$match $boardurl '/' $match;
if (substr($match,0,7) == 'mailto:' || substr($match,0,10) == 'javascript' || !strstr($match'?'))
continue;
if (substr($match,0,strlen($boardurl)) != $boardurl || substr($match,strlen($boardurl),8) == '/Sources' || substr($match,strlen($boardurl),7) == '/Themes' || substr($match,strlen($boardurl),4) == '/img' || substr($match,strlen($boardurl),8) == '/Smileys' || substr($match,strlen($boardurl),8) == '/avatars')
continue;

$urls[$match] = array('url' => $match);
}
}

// Procede only if there are actually URLs in the page
if (count($urls) != 0)
pretty_urls_filter($urls);

// Put the URLs back into the buffer
$context['pretty']['replace_patterns'][] = '~(<a[^>]+href=|<link[^>]+href=|<form[^>]+?action=|<meta property=\"og:url\" content=|<meta property=\"og:image\" content=|<meta property=\"og:video\" content=)(\"[^\"]+\"|\'[^\']+\')~';
foreach ($context['pretty']['replace_patterns'] as $pattern)
$buffer preg_replace_callback($pattern'pretty_buffer_callback'$buffer);

// Restore the script tags
if ($context['pretty']['scriptID'] > 0)
$buffer preg_replace_callback("~\x14([0-9]+)\x14~"'pretty_scripts_restore'$buffer);

// Return the changed buffer.
return $buffer;
}

// Remove and save script tags
function pretty_scripts_remove($match) {
global $context;

$context['pretty']['scriptID']++;
$context['pretty']['scripts'][$context['pretty']['scriptID']] = $match[0];
return "\x14" $context['pretty']['scriptID'] . "\x14";
}

// A callback function to replace the buffer's URLs with their cached URLs
function pretty_buffer_callback($matches) {
global $boardurl$context;

// Is this URL in an attribute, and so will need new quotes?
$addQuotes preg_match('~^[\"\']~'$matches[2]);

// Remove those annoying quotes
$matches[2] = preg_replace('~^[\"\']|[\"\']$~'''$matches[2]);

// Store the parts of the URL that won't be cached so they can be inserted later
preg_match('~PHPSESSID=[^;#&]+~'$matches[2], $PHPSESSID);
preg_match('~(se)?sc=[^;#]+~'$matches[2], $sesc);
preg_match('~' $context['session_var'] . '=[^;#]+~'$matches[2], $session_var);
preg_match('~#.*~'$matches[2], $fragment);

// Rip out everything that won't have been cached
$url_id preg_replace(array('~PHPSESSID=[^;#]+|(se)?sc=[^;#]+|' $context['session_var'] . '=[^;#]+|#.*$~''~\"~''~;+|=;~''~\?;~''~\?$|;$|=$~'), array('''%22'';''?'''), $matches[2]);

// Absolutise relative URLs
if (!preg_match('~^[a-zA-Z]+:|@~'$url_id) && !($url_id == '' && isset($fragment[0])) && SMF != 'SSI')
$url_id $boardurl '/' $url_id;

// Stitch everything back together, clean it up and return
$replacement = isset($context['pretty']['cached_urls'][$url_id]) ? $context['pretty']['cached_urls'][$url_id] : $url_id;
$replacement .= (strpos($replacement'?') === false '?' ';') . (isset($PHPSESSID[0]) ? $PHPSESSID[0] : '') . ';' . (isset($sesc[0]) ? $sesc[0] : '') . (isset($session_var[0]) ? $session_var[0] : '') . (isset($fragment[0]) ? $fragment[0] : '');
$replacement preg_replace(array('~;+|=;~''~\?;~''~\?#|;#|=#~''~\?$|&amp;$|;$|#$|=$~'), array(';''?''#'''), $replacement);
$replacement str_replace('index.php'''$replacement);// Remove index.php, who needs it.
return $matches[1] . ($addQuotes '"' '') . $replacement . ($addQuotes '"' '');
}

// Put the script tags back
function pretty_scripts_restore($match) {
global $context;

return $context['pretty']['scripts'][(int) $match[1]];
}

// Filter URLs
function pretty_urls_filter($urls) {
global $boardurl$context$scripturl;

foreach ($urls as $url_id => $url) {
// Filter Aeva Media
if (strpos($url['url'], 'action=media') !== false){
$context['pretty']['cached_urls'][$url_id] = preg_replace(array('~.*[?;&]action=media;sa=media;in=([0-9]+);(thumba?|preview)(.*)~S','~.*[?;&]action=media;sa=(album|item|media);in=([0-9]+)(.*)~S','~.*[?;&]action=media(.*)~S'), array($boardurl '/media/$2/$1/?$3',$boardurl '/media/$1/$2/?$3',$boardurl '/media/?$1'), $url['url']);
continue;
}
//Filter actions
if (preg_match('`' $scripturl '(.*)action=([^;]+)`S'$url['url'], $matches)){
$context['pretty']['cached_urls'][$url_id] = preg_replace('`' $scripturl '(.*)action=([^;]+)`S'$boardurl '/$2/$1'$url['url']);
continue;
}
//Filter topics
if (preg_match('`' $scripturl '(.*[?;&])topic=([.a-zA-Z0-9]+)(.*)`S'$url['url'], $matches)){
if (strpos($matches[2], '.') !== false)
list ($topic_id$start) = explode('.'$matches[2]);
else{
$topic_id $matches[2];
$start '0';
}
$topic_id = (int) $topic_id;
$start $start != '0' '?start='$start '';
$context['pretty']['cached_urls'][$url_id] = $boardurl '/t/' $topic_id '/' $start $matches[1] . $matches[3];
continue;
}
// Filter boards
if (preg_match('`' $scripturl '(.*[?;&])board=([.0-9]+)(.*)`S'$url['url'], $matches)){
if (strpos($matches[2], '.') !== false)
list ($board_id$start) = explode('.'$matches[2]);
else{
$board_id $matches[2];
$start '0';
}
$board_id = (int) $board_id;
$start $start != '0' $start '/' '';
$context['pretty']['cached_urls'][$url_id] = $boardurl '/b/' $board_id '/' $start $matches[1] . $matches[3];
continue;
}
// None
$context['pretty']['cached_urls'][$url_id] = preg_replace(array('~\"~''~;+|=;~''~\?;~''~\?$|;$|=$~'), array('%22'';''?'''),str_replace("\x12"'\''$url['url']));
}
}

?>


Still have a little bit of work as there is other things I would like to do with it. Thanks for providing a base to start upon.  ;)

ErtugrulBEKTIK

"Fixing any old boards and topics with broken quotes" is not working. Please help me.

perfec2

All my categories/boards urls end with  "?wwwRedirect"   Please how can I fix this?

Kindred

use the correct URL to access your site.

Either you set your site us to be www.yoursite.com and you are trying to access it from just yoursite.com or vice versa.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

eagled2

I'm setting up a webserver for smf on a vps and am thinking of using nginx because its lightweight and want to conserve resource usage. I've seen several posts about how to rewrite prettyurl's to work in nginx that are quite old and a hint that future version may make it easier to work in nginx. Does the latest version of pretty url's work with nginx by default or will i still need to change the rewrite rules?

vbgamer45

No it does not. People have posted the urls in this topic somewhere...
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

eagled2

Thanks I found a couple links already and several copies of rewrites to make it work.  I'll give it a shot afterafter I get the web server installed this weekend.

GleamPlay.com

How do I make it so that my folder /games/ still works?

I read the troublesome page but it only teaches to make 1 page work.
But for example, I got 100 other pages in my /games/ folder, how do I make the whole folder an exception?
For example there are different pages like: /games/game1/, /games/game2/, etc.

Thanks a lot. :)
Gleam - http://gleamplay.com
The SMF to have fun, meet new friends and play games!

Xpresskonami

Am using SMF 2.0.11. I try to buy new domain.net, and am using domain.com , so I decide to redirect my .net to the .com

I make use of 301 redirect in my C/panel. It all redirect perfectly, but my Forum Post & Topic are still on my Old domain (.com) instead of my New Domain (.Net)

I run the repair_settings.php.....but The main problem am facing now is. If I install the pretty url. I won't be able to make new post, and all topic are redirect to old domain. Ie All topic created is in old url domain e.g (Oldurl.com/my-topic-i-created/)

But if I uninstall the pretty url.
All files in my site work well. Both topics and board are in new domain.
(Newurl.com/my-topic-i-created/)

And I want the pretty url mods to work

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Galaxy Computers

I am using a mod called Pretty URL's. I had to change my Admin username from Support Team to SupportTeam then when you click on SupporTeam it shows this url support.mtechama.com/Support Team instead of support.mtechama.com/SupportTeam there is a space between Support and Team. How can fix this?
Wade Morris
Amarillo, Texas

Morris Technologies Computer Support Forum

ZabiinoOo

my website has stopped working as uninstall?

vbgamer45

Get the manual install instructions at http://www.smfhacks.com/smf-package-parser.html and reverse them to unisntall completely if it fails
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

p455w0rd

so..i mean the urls work..but I can do that without a fancy mod..what I need is for the links generated to be changed to the pretty urls, which doesn't happen..EG: /index.php?action=blah should just be /blah in things like the top menu..what exactly is the point of this if it doesn't change the links?

Arantor

This mod does do that, that's the point. If it doesn't, something is wrong with your setup (or it hasn't been enabled properly)

p455w0rd

odd..this is a fresh install (downloaded like a week ago) using the default theme just to be sure it wasn't the theme...i mean if it doesn't work on a default SMF install, I don't feel it's my problem...oh well..too much time wasted already..I'll find a different forum solution for my client, thanks for the reply.

Kindred

just as a note...  it does work just fine with the default theme (and every other theme I have looked at)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: