Advertisement:

Author Topic: .htaccess redirect  (Read 364 times)

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,390
  • Riding the endless highway in the sky.
.htaccess redirect
« 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 -

Code: [Select]

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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,615
    • StoryBB/StoryBB on GitHub
Re: .htaccess redirect
« Reply #1 on: July 12, 2018, 06:27:25 PM »
Last time I did this...

Code: [Select]
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,390
  • Riding the endless highway in the sky.
Re: .htaccess redirect
« Reply #2 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.


Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,615
    • StoryBB/StoryBB on GitHub
Re: .htaccess redirect
« Reply #3 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:

Code: [Select]
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]
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,390
  • Riding the endless highway in the sky.
Re: .htaccess redirect
« Reply #4 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. >:(

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,615
    • StoryBB/StoryBB on GitHub
Re: .htaccess redirect
« Reply #5 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,390
  • Riding the endless highway in the sky.
Re: .htaccess redirect
« Reply #6 on: July 12, 2018, 07:15:50 PM »
.htaccess

Code: [Select]

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


Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,615
    • StoryBB/StoryBB on GitHub
Re: .htaccess redirect
« Reply #7 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...
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,390
  • Riding the endless highway in the sky.
Re: .htaccess redirect
« Reply #8 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.