52533

PHP Permalinks.. how to change?

Question:

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

Answer1:

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 <a href="http://php.pastebin.com/" rel="nofollow">pastebin</a> 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 <a href="http://www.smarty.net" rel="nofollow noreferrer">Smarty</a> 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.

<strong>EDIT:</strong> 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.

<strong>EDIT 2</strong> 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.

<strong>EDIT 3</strong> 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.

<strong>Edit 4</strong> 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!

Answer2:

The <a href="http://php.net/urlencode" rel="nofollow">urlencode</a> 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 <a href="http://php.net/urldecode" rel="nofollow">urldecode</a>.

Recommend

  • Setting attributedText, NSRangeException error
  • How can I make multiple app flavors use the same google-services.json file?
  • Sort by date with jmespath
  • USING block behaves differently in website vs windows form
  • Admin-on-rest, Edit Page - Incorrect Element Error
  • Normal Query on Cassandra using DataStax Enterprise works, but not solr_query
  • Get the output of multiple commands from subprocess.Popen
  • How to change type datatable column [duplicate]
  • Gulp dest() dynamic destination folders based on file names
  • angular 2 websql typings
  • Fitbit oauth2 public API stopped working. Giving error - Sorry Its not you.. Its us
  • Combine rows with same id and delete duplicated rows
  • Auto-incrementation with HSQLDB (2.2.8) + DDLUtils
  • Select Checkbox !== Select Row Table
  • Preventing Internet-accessing-method from delaying a toast popup
  • Accessing Dictionaries VS Accessing Shelves
  • List using with references, changes behavior when used as a member
  • What is the diff. between default.properties and project.properties?
  • Force fading edge on TextView
  • Was there ever a proposal to include the URL fragment into the HTTP request?
  • How to put an object in the air?
  • Unable to run testNG tests from maven
  • Sample deviceQuery cuda program
  • Android studio import problems. (Apktool)
  • How to define a custom accuracy in Keras to ignore samples with a particular gold label?
  • Building JavaFX 2.0 App on Mac, deploying on Windows
  • python selenium scraping tbody
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Request Access Token in Postman for Azure Function App protected by Azure AD B2C
  • How to redirect into different page by user type in php and mysql
  • How do I use libcurl to printf a remote FTP directory listing?
  • java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-ser
  • JQuery: Infinite input select
  • 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs
  • how do i compare two rows and store the similarities of the two rows in another column
  • JavaScript Regex to Match Boundaries of Words with diacritics
  • how to get the location(lat/lng) on google maps v3 from the location(x,y)
  • how to run ejabberd with Erlang on Heroku?
  • how to snap two objects in runtime in unity?
  • Python Flask - GUI for client