News:

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

Main Menu

.htaccess redirect

Started by Sir Osis of Liver, July 12, 2018, 06:04:48 PM

Previous topic - Next topic

Sir Osis of Liver

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.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

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.

Sir Osis of Liver

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.

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

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]

Sir Osis of Liver

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. >:(
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

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.

Sir Osis of Liver

.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

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

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...

Sir Osis of Liver

Hmm, it's commented out, isn't it.  Will give it a try .......

Nope, try the links yourself.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: