开发者

PHP Permalinks.. how to change?

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开发者_StackOverflow社区 are not at all indexed by search engine..

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


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜