News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

SMF: Url rewrite

Started by @NET, June 07, 2005, 07:51:47 AM

Previous topic - Next topic

@NET

Greetings,
I use SMF.

I want to change url`s.
/index.php --->> /index.html
/index.php/board,9.0.html --->> /board_9.0.html
/index.php/topic,7.0.html --->> /board_9.0_topic_7.0.html or /topic_7.0.html

How such it is possible to make?
Thanks!

[Unknown]

Find, Sources/QueryString.php:

elseif (!empty($modSettings['queryless_urls']) && !$context['server']['is_cgi'] && $context['server']['is_apache'])
$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", $buffer);


Replace:

elseif (!empty($modSettings['queryless_urls']) && !$context['server']['is_cgi'] && $context['server']['is_apache'])
$buffer = preg_replace(array('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?"/e', '/"' . preg_quote($scripturl, '/') . '/'), array("'\"' . strtr(\$scripturl, array(\'/index.php\' => \'\')) . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", '"' . strtr($scripturl, array('/index.php' => '/index.html'))), $buffer);


Nest you'll need the rewrite URLs changing it back.... something like:

RewriteEngine On
RewriteRule index.html(.*)$ /path/index.php$1
RewriteRule (board.*)$ /path/index.php/$1
RewriteRule (topic.*)$ /path/index.php/$1

Or similar.

-[Unknown]

@NET

Thanks for the help!
But this code does not work.
Possibly there a Error.

Quote from: [Unknown] on June 07, 2005, 01:32:24 PM
Find, Sources/QueryString.php:

elseif (!empty($modSettings['queryless_urls']) && !$context['server']['is_cgi'] && $context['server']['is_apache'])
$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", $buffer);


Replace:

elseif (!empty($modSettings['queryless_urls']) && !$context['server']['is_cgi'] && $context['server']['is_apache'])
$buffer = preg_replace(array('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?"/e', '/"' . preg_quote($scripturl, '/') . '/'), array("'\"' . strtr(\$scripturl, array(\'/index.php\' => \'\')) . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", '"' . strtr($scripturl, array('/index.php' => '/index.html'))), $buffer);


Nest you'll need the rewrite URLs changing it back.... something like:

RewriteEngine On
RewriteRule index.html(.*)$ /path/index.php$1
RewriteRule (board.*)$ /path/index.php/$1
RewriteRule (topic.*)$ /path/index.php/$1

Or similar.

-[Unknown]

[Unknown]

Well, it's the general idea.  If you want me to fix it, tell me what it does that doesn't work...

-[Unknown]

@NET

Quote from: [Unknown] on June 15, 2005, 05:22:13 AM
Well, it's the general idea.  If you want me to fix it, tell me what it does that doesn't work...

-[Unknown]

Hi

I have written down in QueryString.php and .htaccess

Then i reload a web-page, but page empty <html><body></body></html>

morph

What lines of code did you change. And what were other changes that you have made?

Coming soon!

@NET

Quote from: morph on June 21, 2005, 12:06:12 PM
What lines of code did you change. And what were other changes that you have made?

Sources/QueryString.php

elseif (!empty($modSettings['queryless_urls']) && !$context['server']['is_cgi'] && $context['server']['is_apache'])

$buffer = preg_replace(array('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?"/e', '/"' . preg_quote($scripturl, '/') . '/'), array("'\"' . strtr(\$scripturl, array(\'/index.php\' => \'\')) . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", '"' . strtr($scripturl, array('/index.php' => '/index.html'))), $buffer);

.htaccess
RewriteEngine On
RewriteRule index.html(.*)$ /path/index.php$1
RewriteRule (board.*)$ /path/index.php/$1
RewriteRule (topic.*)$ /path/index.php/$1


J. S.

It would be nice to have the ', $context['page_title'], ' in the URL. Is there any way to do that?

tycms

Reviving a 5-years-old topic...

I want to get the following:
index.php?t=38053.0
instead of
index.php?topic=38053.0

On a test SMF 2.0 RC3 install, I tried the following on QueryString.php.


if (defined('SID') && SID != '')
$buffer = preg_replace(array('/"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', '/"' . preg_quote($scripturl, '/') . '/'), array("'\"' . strtr(\$scripturl, array(\'topic' => \'t')) . '/' . strtr('\$1', '&;=', '//,') . '.html?' . SID . '\$2\"'", '"' . strtr($scripturl, array('/index.php' => '/index.html'))), $buffer);
else
$buffer = preg_replace(array('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', '/"' . preg_quote($scripturl, '/') . '/'), array("'\"' . strtr(\$scripturl, array(\'topic' => \'t')) . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", '"' . strtr($scripturl, array('/index.php' => '/index.html'))), $buffer);


But it doesn't work. What's wrong with it?

Thanks.

tycms

I also tried the following:


$buffer = strtr($buffer, "topic", "t");


This doesn't work either. Nothing changes. Anyone to help please?

SimpleGost

Quote from: @NET on June 07, 2005, 07:51:47 AM
Greetings,
I use SMF.

I want to change url`s.
/index.php --->> /index.html
/index.php/board,9.0.html --->> /board_9.0.html
/index.php/topic,7.0.html --->> /board_9.0_topic_7.0.html or /topic_7.0.html

How such it is possible to make?
Thanks!

I need this PLEASE!

Advertisement: