1

I built an client website with php script purchased recently and the support for script is pathetic, I want the permalinks of the script to be search engine friendly but they're not. They have spaces inbetween which are not at all indexed by search engine..

So, how can I change the permalinks? Thank you all..

regguy
  • 34
  • 4
  • Is the script that you bought have a name? If some of the developers here could get a look at it, we'd be better able to tell you where in the source to make changes. – MidnightLightning Jan 24 '10 at 22:06

2 Answers2

1

If you've got 50 PHP files and an .htaccess file that come with this "script", you'll likely first have to find the programming path that flows through them. If you take a look at the .htaccess file, you should see some ModRewrite lines, which should end with a PHP file name. That's the script that's receiving (and decoding) the permalinks. That file would be a good place to start looking for a hook to rewrite the permalink structure. If you could post the source code (or put it somewhere like pastebin and post the link) for that file, I'd be glad to take a look.

From one of your other comments it sounds like at least part of the script is using the Smarty PHP template engine. If so, if you can find a folder that contains "cache", "templates", and "templates_c" folders (or similar), you can rule that one out as well; that would be the templates used to show the page, and not any of the decode/encode scripts.

EDIT: Looking at your .htaccess file, line 29 looks to the be one that deals with article permalinks, and it points to view.php, and converts what was the permalink into id and title GET variables. Post the source of view.php if you could, and we'll go from there.

EDIT 2 Okay, looking at view.php gained a little more insight. Primarily of which is that there is no decoding function; the Answerscript engine promptly discards the 'title' part of the permalink and only looks up a question by its ID (number following the pipe on the URL query; you can prove this on their demo page by changing the title part of the URL to anything else, and it will still fetch the right page). So, the good news is that there's no decoding function that needs to be updated when you change the encoding function. Unfortunately this does very little to tell us where the encoding function is in the scripts.

The only hint is that the view.php file includes a file called include/functions/import.php, which I'm presuming has function definitions for does_post_exist($PID), update_last_viewed($PID), update_your_viewed($USERID), and update_viewcount_question($PID). Let's see the source of that file to see if there's any other functions in there that would be used for importing. Also, how many files are in the include/functions/ folder? If there's only a few, post all their sources; likely the encoding function is defined in there. If there's a bunch, is there an export.php file in that folder (i.e. the opposite of import.php that was used by view.php)? Post that file's source as it likely has the encoding function.

EDIT 3 There they are: in the main.php file there's a trio of functions: seo_clean_titles, insert_seo_clean_titles, and seo_clean_titles2. insert_seo_clean_titles is a function to be called from within a Smarty template (search all files that have a .tpl extension for {insert name="seo_clean_titles" to see where that's used), and the difference between seo_clean_titles and seo_clean_titles2 is that the first echoes out the result, while the second returns it. However, all three have the line $title = str_replace(" ", "-", $title);, which should be turning all spaces in the title to hyphens. If you're not seeing that result, likely the code is not calling these functions at the right places. You can search through all the .php files and see if anywhere else there's a call to seo_clean_titles or seo_clean_titles2, and make sure the result is being actually used as the final URL.

Edit 4 To add ".html" to the end of all URLs: Here's the line in the template file linking to the question page:

<a href="{$baseurl}/{$ques[i].seo}/{$title}|{$ques[i].PID}">{$ques[i].title|stripslashes}</a>

Change that to:

<a href="{$baseurl}/{$ques[i].seo}/{$title}|{$ques[i].PID}.html">{$ques[i].title|stripslashes}</a>

and the links will have ".html" on the end. You'll then need to modify view.php to strip the ".html" back off again when parsing out the ID number: Right before $pid = intval($ph);, insert the following:

if (strtolower(substr($pid, -5)) == ".html") $pid = substr($pid,0,-5); // Remove ".html" if it exists

That should do it!

MidnightLightning
  • 6,715
  • 5
  • 44
  • 68
  • Hi ML, Thanks a lot for the simple explanation. I do have preg_replace( in 19 files (I did a global search) and uploaded the htaccess file http://php.pastebin.com/m4dcdf8e4 Please have a look. The script is 'answerscript' which is an ask answer php script, however their demo is updated now with working permalinks. The script, when purchased didn't come with working permalink structure for me. Like I said, support doesn't care to update. And, it does have smarty folder (I assume that is an engine) with libs files such as Smarty_Compiler.class, Smarty.class... Thank you! – regguy Jan 25 '10 at 04:00
  • Is it this "Answerscript": http://www.answerscript.com/? Yes, it sounds like it includes a full Smarty engine inside the Answerscript engine; you can likely ignore the whole "smarty" folder while trying to fix the permalink structure, as it will only be dealing with the final display of the page. See my edit above for more on what I gleaned from your `.htaccess` file. – MidnightLightning Jan 25 '10 at 13:11
  • @ MidnightLightning - Thank a LOT! Seriously, you've been amazing. I found view.php content files and have pasted it here http://pastebin.com/m6dc7b983 I guess appending of no. at the last of the url is automated/obvious? It is possible to make permalinks of this type http://www.sawaal.ibibo.com/ that has .html tagged to it at the end.. the site ranks very well on search. I am sorry for asking so many stuffs, am overwhelmed with your support and help for helping me in fixing the permalinks. Appreciate a lot..!! – regguy Jan 25 '10 at 16:37
  • @ MidnightLightning - Function folder contains three files import, main and xml (php files) along with index html file. The import.php was pointing to main and xml file.. The source - (import.php) -> http://pastebin.com/m11b2dccb (main.php) -> http://pastebin.com/m3ec733a6 (xml.php) -> http://pastebin.com/m2f8003ef And, I assume xml has to do something with the structures. Still not sure but I appreciate for your concern on this. Thank you again! Looking to make search engine friendly url with your help.. have a nice time. – regguy Jan 26 '10 at 07:15
  • @ MidnightLightning - Awesome! The spaces are converted into hyphens and I can convert them to underscore now.. thanks a lot for digging it, ML! One last question - How to make the permalinks match sawaal.ibibo.com website. Like I said, it appends "-|4" at the end of the permalinks. Can it be converted into -4.html? (assuming that the ID's can never be eliminated from permalinks). Thanks again. – regguy Jan 26 '10 at 14:59
  • The `seo_clean_titles` function(s) only parse the title of the question; they don't build the full URL that's used to link to the page. If you can find where that function is being used in another PHP page (or search the Smarty templates as indicated in my answer to see if it's being used directly in the display template), and post that code, I'll show you how to modify it. – MidnightLightning Jan 26 '10 at 16:15
  • @MidnightLighting - I executed an 'find all' search in .php pages and also .tpl pages using notepad++, seo_clean_titles was seen in 10+ files and I have uploaded the search results here http://pastebin.com/m7fc55dfb and kindly let me know which is the file source code I should paste or if it's appropriate, I can send you the files too. Thank you for getting back quickly. – regguy Jan 26 '10 at 16:31
  • Hmmm... I'll take `\themes\index.tpl` for 100, please, Alex. Likely that's the main page's display template, and it looks like the insert function is used the same in all the templates, so if we change one, you can change the others the same way. – MidnightLightning Jan 26 '10 at 16:48
  • Alex, here is the index.tpl file http://pastebin.com/m124e260 and yes, I figured out some of the template files were used repeatedly on most/all of the files making it difficult to make a new page. Now I know where I stand when it comes to php coding..this is not easy! – regguy Jan 26 '10 at 17:19
  • AWESOME! You're awesome. I got the permalinks structure just as I wanted.. I removed '|' from the $baseurl code and it displays much like domainname.com/cat/my-name-12.html BUT, there is only one problem I am trying to solve which is the 404 error, this has to do with .htaccess but all the tutorials I found are of wordpress 404 fix. Any help on fixing this? I am unable to view the domainname.com/cat/my-name-12.html page as it throws in 404 Not found error.. I guess 90% of the job is done! Thank you. – regguy Jan 26 '10 at 19:33
  • `view.php` finds the ID number of the question by finding the pipe character ('|') in the URL. If you removed it, you likely broke its ability to find out what ID you were searching for, and would have to put some logic in to find the ID number without the pipe character. – MidnightLightning Jan 26 '10 at 22:16
  • Even with the pipeline it throws in 404 not found error when we try to visit the url, I guess this has to be with rewriterules of some kind. Have tried many of them, failed in redirecting to .html version.. – regguy Jan 27 '10 at 03:24
  • Change `RewriteRule ^([^/.]+)/([^/.]*)?$ view.php?title=$1&id=$2&%{QUERY_STRING}` to `RewriteRule ^([^/.]+)/(.*)?$ view.php?title=$1&id=$2&%{QUERY_STRING}` and that should pick up your .html suffixes. – MidnightLightning Jan 27 '10 at 13:05
  • Update: It strips the css after using the above code in htaccess file. I guess I need to give up now! I better stick to the old permalinks, perhaps stripping the slashes and question mark from url would be the best! The website is http://studentask.com in it's original permalinks. Update: Using old permalinks for the time being. – regguy Jan 27 '10 at 19:30
0

The urlencode function would take care of the spaces in the URL.

For example:

<?php
$base_url = 'http://example.com';
$category = urlencode('some thing');
$item     = urlencode('Name of an item');

echo "<a href=\"{$base_url}/{$category}/{$item}/>{$item}</a>";
?>

This would make the link http://example.com/some+thing/Name+of+an+item/ which a search engine should be fine with.

And, assuming you are using URL rewriting (like mod_rewrite), the values should reach your PHP script as they were before the urlencode function. If not, you can revert them back with urldecode.

Atli
  • 7,855
  • 2
  • 30
  • 43
  • Hi Atli, Thanks a lot for helping me out. I appreciate it a lot. I went into the files and made a search for 'urlencode' in my php script, found a few of them. Do you want me to replace that code with the above code? I guess moderator doesn't allow public links. === // convert the matched php-code to functions $_include_compiled = "_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; $_include_compiled .= " compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */\n\n"; – regguy Jan 24 '10 at 19:56
  • That bit of code you posted doesn't seem to be the right instance of `urlencode` that you're looking for (though it does seem to be a unique interpretation of the Smarty template engine). Any other occurrences? – MidnightLightning Jan 24 '10 at 22:17
  • I checked the client area of the script and received my newer version. There was a read me file in the new version that had instructions to update the sql and replace some codes. Now the permalinks structure are something like this. http://Domainname.com/Arts-Humanities/how-are-you-doing?-|4 I am not sure if the "-|4" appended at the end of the question are reliable and friendly with search engine. Any thoughts on that? Thank you again. – regguy Jan 25 '10 at 04:21