Customizing SMF > SMF Coding Discussion

.htaccess redirect

(1/2) > >>

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 -


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


--- End code ---

Redirects first link to new domain main index, action is lost.

Arantor:
Last time I did this...


--- Code: ---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]

--- End code ---

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.

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:


--- Code: ---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]
--- End code ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version