Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Sir Osis of Liver on July 12, 2018, 06:04:48 PM

Title: .htaccess redirect
Post by: Sir Osis of Liver on July 12, 2018, 06:04:48 PM
Trying to get this -

hxxps://www.olddomain.com/bbs/index.php?action=printpage;topic=364.0

to redirect to this -

hxxps://www.newdomain.com/forum/index.php?action=printpage;topic=364.0

Currently using this -



RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} olddomain.com [NC]
RewriteRule ^(.*)$ https://www.newdomain.com/forum/index.php [R=301,NC]



Redirects first link to new domain main index, action is lost.
Title: Re: .htaccess redirect
Post by: Arantor on July 12, 2018, 06:27:25 PM
Last time I did this...

RewriteCond %{HTTP_HOST} !^www\.olddomain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/?(.*)         https://www.newdomain.com/$1 [L,R,NE]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]


First part fixes requests from the old domain to the new (and handles cases of empty host header), the second part ensures using HTTPS - and in all cases preserving the query string.
Title: Re: .htaccess redirect
Post by: Sir Osis of Liver on July 12, 2018, 06:38:36 PM
Doesn't work, get page can't be displayed error for old printpage link.  Domain redirect works.  The subdir is different on old and new.

Title: Re: .htaccess redirect
Post by: Arantor on July 12, 2018, 06:44:32 PM
That's what I get for just digging out my material that just has the forum at top level.

I'd assume you could tweak it thus:

RewriteCond %{HTTP_HOST} !^www\.olddomain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/bbs/?(.*)         https://www.newdomain.com/forum/$1 [L,R,NE]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
Title: Re: .htaccess redirect
Post by: Sir Osis of Liver on July 12, 2018, 06:52:07 PM
Still doesn't work.  It has to redirect from olddomain/bbs/ to newdomain/forum/ without losing the action.  That's the part I can't get. >:(
Title: Re: .htaccess redirect
Post by: Arantor on July 12, 2018, 06:57:39 PM
I don't see why it would lose the action given that it keeps literally everything in the URL after the bbs/ part...

The site these rules came from work correctly, I can only assume you're doing something weird about it - because it's not like I have enough information to debug this, like, say actual examples of where these things end up (because details actually matter). This of course assumes the edits to the domains etc. were made correctly because things like escaping matter here.
Title: Re: .htaccess redirect
Post by: Sir Osis of Liver on July 12, 2018, 07:15:50 PM
.htaccess



RewriteCond %{HTTP_HOST} !^www\.busconversions\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/bbs/?(.*)         https://www.busconversionmagazine.com/forum/$1 [L,R,NE]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.busconversionmagazine.com/$1 [R=301,L]


#RewriteEngine on
#RewriteBase /
#RewriteCond %{HTTP_HOST} busconversions.com [NC]
#RewriteRule ^(.*)$ #https://www.busconversionmagazine.com/forum/index.php [R=301,NC]



Old link - https://www.busconversions.com/bbs/index.php?action=printpage;topic=364.0

New link - https://www.busconversionmagazine.com/forum/index.php?action=printpage;topic=364.0

Title: Re: .htaccess redirect
Post by: Arantor on July 12, 2018, 07:19:25 PM
How about you take out the chunk of code at the bottom that is performing a redirect without keeping the query string? You know, your original code that didn't work...
Title: Re: .htaccess redirect
Post by: Sir Osis of Liver on July 12, 2018, 07:27:14 PM
Hmm, it's commented out, isn't it.  Will give it a try .......

Nope, try the links yourself.