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.

SEO url rewrite

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:
CodeDownload  
ob_start();



Replace with:

CodeDownload  
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:

CodeDownload  
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.

CodeDownload  
<?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!!
Anyone?
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.
Great it works perfect now!
Thank you so much for the help!
Thank you...
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

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...
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 ??

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^^

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
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
I will try to use it in public_html folder i think it might solve the problem. will let you know ...

thanks
wadday

Quote

xandros wrote:
Replace the line with this code:

CodeDownload  
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.

Quote

xandros wrote:
Replace the line with this code:

CodeDownload  
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.
I followed the debating since the beginning
I apply what you said, but I review error 404

thank you for helping me :|
Good work! I'll try it.
Jet always a 404 error
Cool. Thanks for the info and sharing it with us.

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

:D
Thread Information
Author
Replies
19 posts
Views
14,868 times
Last Post
Last updated on 10 years ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can 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.
Users who participated in discussion: Quartzkyte, noob, wadday, Basti, phpmania, Splash, GreenMoo, googlebot, sathishIPL, sumaila71, diane09