SMF Support > Server Performance and Configuration

Old links with html not working in nginx

(1/2) > >>

spiros:
I have links in this format:

https://www.translatum.gr/forum/index.php/topic,2884.0.html

But when switching to nginx instead of apache they will lead to an error page outside the forum.

How can I either add a rule to accept those links in nginx or run a regex in the dB to change to standard format, I.e. from this format:


--- Code: ---https://www.translatum.gr/forum/index.php/topic,2884.0.html
--- End code ---

to this:


--- Code: ---https://www.translatum.gr/forum/index.php?topic=2884.0
--- End code ---

GigaWatt:
You could probably do it with this script ;). Do a database backup first and leave $doit = 'No' (do a test run first ;)).

Note: It doesn't support wildcards (*).

spiros:
Quite complex script, not sure if it will fix the style of urls I mention.

I had something like this in mind:


--- Code: ---UPDATE smf_messages SET body = REPLACE(body, 'oldURL', 'newURL') WHERE ID_BOARD = 1
--- End code ---

but I am not sure of how to implement the REGEXP_REPLACE to match the URL style change (I am using MariaDB 10.2)

GigaWatt:
Try the script I posted with these settings.


--- Code: ---$oldURL = 'translatum.gr/forum/index.php/topic,';
$oldDir = '/12345';
$newURL = 'translatum.gr/forum/index.php?topic=';
$newDir = '/12345';
$doit = 'No';
--- End code ---

Let it run, it'll probably change the URL you posted to something like this.


--- Code: ---https://www.translatum.gr/forum/index.php?topic=2884.0.html
--- End code ---

The problem is, how to remove the .html at the end now :S. Hmmm...

Maybe try another run of the script, but do it with these settings.


--- Code: ---$oldURL = '.0.html';
$oldDir = '/12345';
$newURL = '.0';
$newDir = '/12345';
$doit = 'No';
--- End code ---

Now this should fix the links to topics (ending with .0), but if there are some links that lead to a topic's page (.20, .30, .40), you'll probably have to fix them with more runs :S.

spiros:
The problem is that there are also external URLs matching "0.html". These links will be broken.

Also, there are links to messages like these:


--- Code: ---https://www.translatum.gr/forum/index.php/topic,696.msg2729.html#msg2729
--- End code ---

For the time being, this is the best I could get at with 3 queries:


--- Code: ---UPDATE smf_messages SET body = REPLACE(body, 'translatum.gr/forum/index.php/topic,', 'translatum.gr/forum/index.php?topic=') WHERE ID_BOARD = 27
UPDATE smf_messages SET body = REPLACE(body, '.0.html', '.0') WHERE ID_BOARD = 27
UPDATE smf_messages SET body = REPLACE(body, '.html#msg', '#msg') WHERE ID_BOARD = 27

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version