News:

Wondering if this will always be free?  See why free is better.

Main Menu

friendly url's

Started by wibo, November 02, 2006, 02:21:16 PM

Previous topic - Next topic

wibo

SMF Version: SMF 1.1 RC3
My forum is not indexed in Google (only the first page - no topics)

I enabled Search engine friendly Url's in admin but it does not work on my forum.
I've read the whole afternoon almost all info about friendly url's in this community but really don't know what to do, what to ask to my hoster.

My server info:
--------------
_SERVER["SERVER_SOFTWARE"]   Apache/1.3.37 (Unix)
_SERVER["GATEWAY_INTERFACE"]   CGI/1.1
_SERVER["SERVER_PROTOCOL"]   HTTP/1.1

Do I need mod_rewrite?
Do I need AcceptPathInfo? (no info in phpinfo() )
PHP be an Apache module (not CGI)?

Thanks in advance,
Wibo

Oldiesmann

PHP needs to be running as an Apache module for this to work. AcceptPathInfo is only needed if you're using Apache 2.
Michael Eshom
Christian Metal Fans

wibo

Quote from: Oldiesmann on November 02, 2006, 02:29:50 PM
PHP needs to be running as an Apache module for this to work. AcceptPathInfo is only needed if you're using Apache 2.

No mod_rewrite?

How can I see if PHP runs as an Apache module?


青山 素子

To tell how PHP is running, make a phpinfo file and see what it says for "Server API" (What is phpinfo.php?).

If PHP is running as a CGI, see if you can get a custom php.ini, or if the host can add "cgi.fix_pathinfo = 1" to their php.ini.
Motoko-chan
Director, Simple Machines

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


wibo

Quote from: Motoko-chan on November 02, 2006, 03:49:47 PM
To tell how PHP is running, make a phpinfo file and see what it says for "Server API" (What is phpinfo.php?).

If PHP is running as a CGI, see if you can get a custom php.ini, or if the host can add "cgi.fix_pathinfo = 1" to their php.ini.

Hello Motoko-chan,

Server Api =  CGI/FastCGI

wibo

I've seen the php.ini file.

cgi.fix_pathinfo = 1  is already written inside the ini file

Daniel15

My host runs PHP as CGI as well (due to the use of PHP SuExec). Because of this, SMF thinks that the friendly URL's won't work properly (even though they do). As you can see at http://www.daniel15.com/, I managed to get friendly URL's working. This is thanks to a piece of code posted a while ago by Oldiesmann.

Basically, open index.php, and find:

// Check if compressed output is enabled, supported, and not already being done.


Add before:

if(empty($_REQUEST['action']) && (isset($_REQUEST['board']) || isset($_REQUEST['topic'])))
{
if(empty($modSettings['queryless_urls']))
{
// This is surprisingly simple... Figure out whether it's a board or a topic, and replace a few characters
if(strpos(strtolower($_SERVER['REQUEST_URI']), '/board,'))
{
// We're really only interested in what follows "/board,"...
$string = substr($_SERVER['REQUEST_URI'], strpos(strtolower($_SERVER['REQUEST_URI']), '/board,') + 7);

// This is really quite simple - replace every "/" with a ";", every "," with an "=" and get rid of ".html"...
$location = $scripturl . '?board=' . str_replace(array('/', ',', '.html'), array(';', '=', ''), $string);

header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
}
elseif(strpos(strtolower($_SERVER['REQUEST_URI']), '/topic,'))
{
// We only need what's after "/topic,"...
$string = substr($_SERVER['REQUEST_URI'], strpost(strtolower($_SERVER['REQUEST_URI']), '/topic,') + 7);

// Again, just replace slashes with semicolons, commas with equal signs and get rid of the .html...
$location = $scripturl . '?topic=' . str_replace(array('/', ',', '.html'), array(';', '=', ''), $string);

header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
}
}
// Only do this if we're just viewing a board or a topic - "board=" or "topic=" could be there in other situations as well...
else
{
// Still just a simple matter of replacing things, although a bit more work is required for topics...
if(strpos(strtolower($_SERVER['REQUEST_URI']), 'board='))
{
// Get whatever follows the "board="
$string = substr($_SERVER['REQUEST_URI'], strpos(strtolower($_SERVER['REQUEST_URI']), 'board=') + 6);

// Reverse of what we did above - replace semicolons with slashes, and equal signs with commas.
str_replace(array(';', '='), array('/', ','), $string);

// Don't forget the .html...
$string .= '.html';

$location = $scripturl . '/board,' . $string;

header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
}
elseif(strpos(strtolower($_SERVER['REQUEST_URI']), 'topic='))
{
// Get whatever follows the "topic="
$string = substr($_SERVER['REQUEST_URI'], strpos(strtolower($_SERVER['REQUEST_URI']), 'topic=') + 6);

// Split off the anchor string from the rest of it...
if(strpos($string, '#'))
{
// Where does the anchor string start?
$pos = strpos($string, '#');

// Isolate the anchor part from the rest of it
$anchorstring = substr($string, $pos);

// Now we just drop that part from the string...
str_replace($anchorstring, '', $string);
}
else
{
$anchorstring = '';
}

// Replace again
str_replace(array(';', '='), array('/', ','), $string);

// Add the .html
$string .= '.html';

$location = $scripturl . '/topic,' . $string . $anchorstring;

// Redirect
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
}
}
}

Then, save it, and check if friendly URL's are working. If not, make sure they're enabled in the SMF admin section.
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

wibo

#7
Yes!!!!!! Great Daniel15.

Thank you very much!!!!

Can I ask you two more questions?

- is the site slower with the code I've added (it seems so to me)
- if google indexs the friendly url's and a google user clicks on a friendly url does the user goes to the correct board or do I have to add more code to convert the friendly url's in default url's again?



Advertisement: