Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.
Navigation

SEO url rewrite

Last updated on 11 years ago
noobnoob
Posted 12 years ago
Hi,

Somewhere on the PF mods forum I found a small mod to rewrite urls to SEO urls.
I already asked my question there, but I'm not getting a response there.

The mod:

Open maincore.php

Find:
ob_start();


Replace with:

function rewrite_urls($buf) {
if(!substr_count($_SERVER[REQUEST_URI],"administration"))
{
$buf = preg_replace('#readarticle\.php\?article_id=([0-9]*?)(\'|")#si', 'read-article\1.html\2', $buf);
$buf = preg_replace('#articles\.php\?cat_id=([0-9]*?)(\'|")#si', 'articles_cat\1.html\2', $buf);
$buf = preg_replace('#articles\.php#si', 'articles.html', $buf);
$buf = preg_replace('#downloads\.php\?cat_id=([0-9]*?)(\'|")#si', 'downloads_cat\1.html\2', $buf);
$buf = preg_replace('#downloads\.php\?cat_id=([0-9]*?)(&|&)download_id=([0-9]*?)(\'|")#si', 'downloads\1-file-\3.html\4', $buf);
$buf = preg_replace('#downloads\.php#si', 'downloads.html', $buf);
$buf = preg_replace('#faq\.php\?cat_id=([0-9]*?)(\'|")#si', 'faq_cat\1.html\2', $buf);
$buf = preg_replace('#faq\.php#si', 'faq.html', $buf);
$buf = preg_replace('#weblinks\.php\?cat_id=([0-9]*?)(\'|")#si', 'links_cat\1.html\2', $buf);
$buf = preg_replace('#weblinks\.php\?cat_id=([0-9]*?)(&|&)weblink_id=([0-9]*?)(\'|")#si', 'links_cat\1-linkid-\3.html\4', $buf);
$buf = preg_replace('#weblinks\.php#si', 'links.html', $buf);
$buf = preg_replace('#news_cats\.php#si', 'news-categories.html', $buf);
$buf = preg_replace('#news\.php\?readmore=([0-9]*?)(\'|")#si', 'readnews-\1.html\2', $buf);
$buf = preg_replace('#contact\.php#si', 'contacts.html', $buf);
$buf = preg_replace('#photogallery\.php\?album_id=([0-9]*?)(\'|")#si', 'gallery-album\1.html\2', $buf);
$buf = preg_replace('#photogallery\.php\?photo_id=([0-9]*?)(\'|")#si', 'gallery-photo\1.html\2', $buf);
$buf = preg_replace('#showphoto\.php\?photo_id=([0-9]*?)(\'|")#si', 'showphoto\1.html\2', $buf);
$buf = preg_replace('#photogallery\.php#si', 'gallery.html', $buf);
$buf = preg_replace('#search\.php\?stype=f#si', 'search-f.html', $buf);
$buf = preg_replace('#search\.php#si', 'search.html', $buf);
$buf = preg_replace('#profile\.php\?lookup=([0-9]*?)(\'|")#si', 'profile-\1.html\2', $buf);
$buf = preg_replace('#print\.php\?type=N(&|&)item_id=([0-9]*?)(\'|")#si', 'print_news\2.html\3', $buf);
$buf = preg_replace('#print\.php\?type=A(&|&)item_id=([0-9]*?)(\'|")#si', 'rint_article\2.html\3', $buf);
$buf = preg_replace('#register\.php#si', 'register.html', $buf);
$buf = preg_replace('#lostpassword\.php#si', 'lostpassword.html', $buf);
$buf = preg_replace('#viewpage\.php\?page_id=([0-9]*?)(\'|")#si', 'viewpage\1.html\2', $buf);
}
return $buf;
}

// Start Output Buffering
ob_start("rewrite_urls");


And I had to create a .htaccess file with this content:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^articles\.html$ articles.php [N]
RewriteRule ^articles_cat([0-9]+)\.html$ articles.php?cat_id=$1 [L]
RewriteRule ^read-article([0-9]+)\.html$ readarticle.php?article_id=$1 [L]
RewriteRule ^index\.html$ index.php [N]
RewriteRule ^downloads\.html$ downloads.php [N]
RewriteRule ^faq\.html$ faq.php [N]
RewriteRule ^links\.html$ weblinks.php [N]
RewriteRule ^news-categories\.html$ news_cats.php [N]
RewriteRule ^news\.html$ news.php [N]
RewriteRule ^readnews-([0-9]+)\.html$ news.php?readmore=$1 [L]
RewriteRule ^contacts\.html$ contact.php [N]
RewriteRule ^gallery\.html$ photogallery.php [N]
RewriteRule ^search-f\.html$ search.php?stype=f [N]
RewriteRule ^search\.html$ search.php [N]
RewriteRule ^profile-([0-9]+)\.html$ profile.php?lookup=$1 [L]
RewriteRule ^gallery-album([0-9]+)\.html$ photogallery.php?album_id=$1 [L]
RewriteRule ^gallery-photo([0-9]+)\.html$ photogallery.php?photo_id=$1 [L]
RewriteRule ^showphoto([0-9]+)\.html$ showphoto.php?photo_id=$1 [L]
RewriteRule ^downloads_cat([0-9]+)\.html$ downloads.php?cat_id=$1 [L]
RewriteRule ^downloads_cat([0-9]+)-file([0-9]+)\.html$ downloads.php?cat_id=$1&download_id=$2 [L]
RewriteRule ^faq_cat([0-9]+)\.html$ faq.php?cat_id=$1 [L]
RewriteRule ^links_cat([0-9]+)\.html$ weblinks.php?cat_id=$1 [L]
RewriteRule ^links_cat([0-9]+)-linkid-([0-9]+)\.html$ weblinks.php?cat_id=$1&weblink_id=$2 [L]
RewriteRule ^print_news([0-9]+)\.html$ print.php?type=N&item_id=$1 [L]
RewriteRule ^print_article([0-9]+)\.html$ print.php?type=A&item_id=$1 [L]
RewriteRule ^register\.html$ register.php [N]
RewriteRule ^lostpassword\.html$ lostpassword.php [N]
RewriteRule ^viewpage([0-9]+)\.html$ viewpage.php?page_id=$1 [L]


I did this all and my site works without errors, but it seems that the urls are not rewritten.
For example http://www.site.com/viewpage.php?page_id=1 must be rewritten to http://www.site.com/viewpage1.html. Unfortunately it's still http://www.site.com/viewpage.php?page_id=1.
When I test this function with a simple page it actually does work.

<?php

function rewrite_urls($buf) {
if(!substr_count($_SERVER[REQUEST_URI],"administration"))
{
$buf = preg_replace('#readarticle\.php\?article_id=([0-9]*?)(\'|")#si', 'read-article\1.html\2', $buf);
$buf = preg_replace('#articles\.php\?cat_id=([0-9]*?)(\'|")#si', 'articles_cat\1.html\2', $buf);
$buf = preg_replace('#articles\.php#si', 'articles.html', $buf);
$buf = preg_replace('#downloads\.php\?cat_id=([0-9]*?)(\'|")#si', 'downloads_cat\1.html\2', $buf);
$buf = preg_replace('#downloads\.php\?cat_id=([0-9]*?)(&|&)download_id=([0-9]*?)(\'|")#si', 'downloads\1-file-\3.html\4', $buf);
$buf = preg_replace('#downloads\.php#si', 'downloads.html', $buf);
$buf = preg_replace('#faq\.php\?cat_id=([0-9]*?)(\'|")#si', 'faq_cat\1.html\2', $buf);
$buf = preg_replace('#faq\.php#si', 'faq.html', $buf);
$buf = preg_replace('#weblinks\.php\?cat_id=([0-9]*?)(\'|")#si', 'links_cat\1.html\2', $buf);
$buf = preg_replace('#weblinks\.php\?cat_id=([0-9]*?)(&|&)weblink_id=([0-9]*?)(\'|")#si', 'links_cat\1-linkid-\3.html\4', $buf);
$buf = preg_replace('#weblinks\.php#si', 'links.html', $buf);
$buf = preg_replace('#news_cats\.php#si', 'news-categories.html', $buf);
$buf = preg_replace('#news\.php\?readmore=([0-9]*?)(\'|")#si', 'readnews-\1.html\2', $buf);
$buf = preg_replace('#contact\.php#si', 'contacts.html', $buf);
$buf = preg_replace('#photogallery\.php\?album_id=([0-9]*?)(\'|")#si', 'gallery-album\1.html\2', $buf);
$buf = preg_replace('#photogallery\.php\?photo_id=([0-9]*?)(\'|")#si', 'gallery-photo\1.html\2', $buf);
$buf = preg_replace('#showphoto\.php\?photo_id=([0-9]*?)(\'|")#si', 'showphoto\1.html\2', $buf);
$buf = preg_replace('#photogallery\.php#si', 'gallery.html', $buf);
$buf = preg_replace('#search\.php\?stype=f#si', 'search-f.html', $buf);
$buf = preg_replace('#search\.php#si', 'search.html', $buf);
$buf = preg_replace('#profile\.php\?lookup=([0-9]*?)(\'|")#si', 'profile-\1.html\2', $buf);
$buf = preg_replace('#print\.php\?type=N(&|&)item_id=([0-9]*?)(\'|")#si', 'print_news\2.html\3', $buf);
$buf = preg_replace('#print\.php\?type=A(&|&)item_id=([0-9]*?)(\'|")#si', 'rint_article\2.html\3', $buf);
$buf = preg_replace('#register\.php#si', 'register.html', $buf);
$buf = preg_replace('#lostpassword\.php#si', 'lostpassword.html', $buf);
$buf = preg_replace('#viewpage\.php\?page_id=([0-9]*?)(\'|")#si', 'viewpage\1.html\2', $buf);
}
return $buf;
}

// Start Output Buffering
ob_start("rewrite_urls");
?>
<html>
<body>
<a href='http://www.site.com/viewpage.php?page_id=1'>Page 1</a>
</body>
</html>
<?php

ob_end_flush();

?>


In this example <a href='http://www.site.com/viewpage.php?page_id=1'>Page 1</a> is rewritten to <a href='http://www.site.com/vviewpage1.html'>Page 1</a>

So the function is correct, but it doesn't work with php-fusion.
Can someone help me to get this working?

Thanks in advance!!
noobnoob
Posted 12 years ago
Anyone?
G
GreenMoo
Posted 12 years ago
Go into themes/templates/footer.php
See the line "echo handle_output($output);"
If you change it to "echo rewrite_urls(handle_output($output));"
...
It might work ;)

If it does; then package up all the changes you have made and submit it somewhere; it would be a truly amazing mod (.htaccess, themes/templates/footer.php) resubmit to moddb perhaps.
noobnoob
Posted 12 years ago
Great it works perfect now!
Thank you so much for the help!
Edited by noob on 10-10-2008 19:45, 12 years ago
QuartzkyteQuartzkyte
Posted 12 years ago
Thank you...
www.php-fusion.co.uk/images/smiley/cool.gif
Mike
---------------------------------------
Quartzkyte, admin @ French N.S.S.
S
sathishIPL
Posted 12 years ago
Hi thanks For the great Mod.....

It Almost Works For me .....

I am having a error...in the head part of the site ..when i click the Rewrite links



Quote

Notice: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in /home/theiplac/public_html/maincore.php on line 54



Can Anyone Tell me the Suggestion? or Help me
W
wadday
Posted 12 years ago

Quote

Notice: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in /home/wadday/public_html/fusion/maincore.php on line 55


I am getting this error but the functions work very well.. its seems that in the maincore.php file on line 55 i am having

Quote

if(!substr_count($_SERVER[REQUEST_URI],"administration"wink)


anyone got any idea...
Life is Super cool - Just the way it is
--------------------------------
Software Developer - VueJS/Laravel
Edited by wadday on 02-12-2008 13:48, 12 years ago
W
wadday
Posted 12 years ago
what if i remove if(!substr_count($_SERVER[REQUEST_URI],"administration"wink) from maincore.php. it works fine is there any other problem could happen ??
Life is Super cool - Just the way it is
--------------------------------
Software Developer - VueJS/Laravel
Edited by wadday on 03-12-2008 10:19, 12 years ago
BastiBasti
Posted 12 years ago

Quote

wadday wrote:
what if i remove if(!substr_count($_SERVER[REQUEST_URI],"administration")) from maincore.php. it works fine is there any other problem could happen ??



If you remove the if()-part, then you must remove the following { and } too.
But I don't know if the administration will work correctly then, but you can take a try^^
[PHP-Fusion Crew Member & Admin from June 2008 - December 2010]

http://basti2web.de - Support Site for my infusions
W
wadday
Posted 12 years ago

Quote

slaughter wrote:

Quote

wadday wrote:
what if i remove if(!substr_count($_SERVER[REQUEST_URI],"administration")) from maincore.php. it works fine is there any other problem could happen ??



If you remove the if()-part, then you must remove the following { and } too.
But I don't know if the administration will work correctly then, but you can take a try^^


of course that has to be removed.

have a look i have removed that line with { } . it works fine just want to know is that for a security reason or not?

here is the test site link http://www.wadday.com/fusion/index.php

thanks
wadday
Life is Super cool - Just the way it is
--------------------------------
Software Developer - VueJS/Laravel
W
wadday
Posted 12 years ago
that mean we must have that function .. so how can i fix that error what has gone wrong...

Quote

Notice: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in /home/wadday/public_html/fusion/maincore.php on line 55
Life is Super cool - Just the way it is
--------------------------------
Software Developer - VueJS/Laravel
W
wadday
Posted 12 years ago
I will try to use it in public_html folder i think it might solve the problem. will let you know ...

thanks
wadday
Life is Super cool - Just the way it is
--------------------------------
Software Developer - VueJS/Laravel
G
googlebot
Posted 12 years ago

Quote

xandros wrote:
Replace the line with this code:

if(!substr_count($_SERVER['REQUEST_URI'],"administration"))


Note that $_SERVER['REQUEST_URI'] and not $_SERVER[REQUEST_URI]

It is assuming there is a constant instead of a string value.

And as xandros has stated three times, doing this will fix your issue. The constant is assumed because of the missing quotes. I don't know why xandros had to post three times - the point should have been obvious: to replace the line with his line.
Visit the new home of the merge between Hacking Vs. Security and Security Override!
My copyright removal has been switched over from HvS to SecurityOverride.
G
googlebot
Posted 12 years ago

Quote

xandros wrote:
Replace the line with this code:

if(!substr_count($_SERVER['REQUEST_URI'],"administration"))


Note that $_SERVER['REQUEST_URI'] and not $_SERVER[REQUEST_URI]

It is assuming there is a constant instead of a string value.

And as xandros has stated three times, doing this will fix your issue. The constant is assumed because of the missing quotes. I don't know why xandros had to post three times - the point should have been obvious: to replace the line with his line.
Visit the new home of the merge between Hacking Vs. Security and Security Override!
My copyright removal has been switched over from HvS to SecurityOverride.
P
phpmania
Posted 11 years ago
I followed the debating since the beginning
I apply what you said, but I review error 404

thank you for helping me :|
S
sumaila71
Posted 11 years ago
Good work! I'll try it.
P
phpmania
Posted 11 years ago
Jet always a 404 error
D
diane09
Posted 11 years ago
Cool. Thanks for the info and sharing it with us.

Regards,
Diane
Pret travaux
SplashSplash
Posted 11 years ago
Using manual edit is best... you may use links like:
fusionsite.com/news-title-n1.html

:D
Igor Ferreira Cemim
PHP-Fusion Brazil staff member.
My site (portuguese): http://desenvolvedorweb.tk/
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
You cannot set up a bounty in this discussion thread.
Moderator: Support Team
Users who participated in discussion: Quartzkyte, noob, wadday, Basti, phpmania, Splash, GreenMoo, googlebot, sathishIPL, sumaila71, diane09,