301 Redirect from SMF to Wordpress

Started by TabletPCPro, May 16, 2014, 05:36:48 AM

Previous topic - Next topic

TabletPCPro

I need to redirect some URLs from my SMF forum to a Wordpress site.
The Wordpress site is installed in the root, and the SMF forum in installed in the forum folder.

I'm using the following code in an .htaccess file, and I have the .htaccess file in the forum folder.
But this is not working, please help me figure out why it is not working:

Options +FollowSymLinks
RewriteEngine on
Redirect 301 /forum/index.php?topic=163.0 http: //www . hxxp:androidtabletpcsupport.com/2014/05/use-voip-android-tablets/ [nonactive]


Thanks in advance for the help

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

TabletPCPro

Thanks for the link, but I have read that page in addition to many other pages on the topic of using htaccess to do a 301 redirect and none of them help me understand why the code I'm using doesn't work. 

Can someone be more helpful and provide more specific help?

Kindred

Because the code that you used is not correct.

The link that I proved has the proper rewrite code...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

TabletPCPro

I have worked out part of the problem with this redirect.
The original "Redirect To" URL is a Wordpress' dynamic URL which cannot be resolved by the server.  If I use the default permalink: http://www .androidtabletpcsupport.com/?p=484 then that side works fine.

The problem I'm still having is the "Redirect From" side of the statement.
"/forum/index.php?topic=163.0" is an SMF dynamic URL and the server cannot resolve this.

The problem with the redirect is in the syntax - You cannot use a RewriteRule to match a query string from a dynamic url.
RewriteRule is for request_uri matching.

www.somesite.com/some/folder/index.php?id=23&name=xyz
                                                                  ^
       It can figure out the request up until after the index.php in this example path

How do I convert the SMF dynamic URL to a regular expression?

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

TabletPCPro

Dude, if that link was helpful, I would have solved this days ago. I have googled this question for days and nothing helps. You obviously do not know the solution since all you can do is send me a useless link.  I obviously don't have the technical knowledge to interpret the info.

Please, can someone provide more specific help!

Kindred

http://www.cheatography.com/davechild/cheat-sheets/mod-rewrite/


You have not been clear what you are trying to do.

First you said that you want to direct specific thread to bounce to your wordpress... (which BTW, seems like a stupid idea to me... but, none-the-less)
You don't indicate if the forum and the wordpress installation are on the same server/domain...

Then you talk ab out regex...   why do you need regex, if you are pointing specific threads whcih you KNOW the URL of to a ne wordpress link which you KNOW the url of?

it's a one to one - no regex needed.


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/forum/index.php?topic=163$ http://www.androidtabletpcsupport.com/2014/05/use-voip-android-tablets/ [NC,R=301,L]
RewriteRule ^/forum/index.php?topic=164$ http://www.androidtabletpcsupport.com/2014/05/another-blog-post/ [NC,R=301,L]
RewriteRule ^/forum/index.php?topic=165$ http://www.androidtabletpcsupport.com/2014/05/yet-another-blog-post/ [NC,R=301,L]


Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

TabletPCPro

Thanks for the help, but your code is not working.  I placed the .htaccess file in both the root, and the folder where SMF is installed, and the redirect does not happen.  When I run a trace, it is stopping at "index.php?"  which is why I was thinking that I need to use the regex instead of the dynamic URL.

Same host, same server, same domain, Wordpress in in the root, SMF is in the /forum folder.

I want to redirect the SMF URL to the Wordpress URL.

.htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/forum/index.php?topic=163$ http://www .androidtabletpcsupport.com/?p=484 [NC,R=301,L]

I even tried putting this in the Webroot, and it did not help:
.htaccess
rewriteengine on
rewritebase /
rewritecond %{HTTP_HOST} ^www.androidtabletpcsupport.com$ [OR]
rewritecond %{HTTP_HOST} ^androidtabletpcsupport.com$
rewriterule ^support\/forum\/index\.php?topic=163\.0$ "http\:\/\/androidtabletpcsupport\.com\/?p=484\/" [R=301,L]

Thanks for the cheat-sheet, that is very helpful.

Any other ideas would be appreciated.

Kindred

For the love of gods, learn to use code tags?

As for the URL I used.. Oops...  Have to escape the question marks...  /?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

TabletPCPro

The purpose of forums like this one is to get help, right?

Chen Zhen

TabletPCPro,

  Kindred is asking you to use bbc code tags for the .htaccess code so that it is more legible within your posts.
Please understand that this is what those bbc code tags are designed for.

  You do not have to use a .htaccess file to do this although it can be done.

  If using a portal block, I suggest using the HTTP request variable along with the SMF redirectexit function. If you are doing a manual edit then I suggest editing ../Sources/Display.php whereas you can substitute the $topic global for the HTTP request from the codes I am going to post below.

Here are some basic drawn out examples (not entirely short hand so that you understand how to edit it/them).
Only use one of them depending on exactly what you want to do. Change your topic id's and url redirects to your specifics.




Portal block examples.

Single array:

$myTopics = array(1,3);
$queryTopic = !empty($_REQUEST['topic']) ? (int)$_REQUEST['topic'] : 0;

if (in_array($queryTopic, $myTopics))
redirectexit('http://example.com/read_this.html');





Multidimensional Array:

$myTopics = array(1 => 'http://example.com/mypage1', 3 => 'http://example.com/mypage2');
$queryTopic = !empty($_REQUEST['topic']) ? (int)$_REQUEST['topic'] : 0;

if (in_array($queryTopic, array_keys($myTopics)))
redirectexit($myTopics[$queryTopic]);





Manual edit via FTP to file: ../Sources/Display.php

find:

// The central part of the board - topic display.
function Display()
{
global $scripturl, $txt, $modSettings, $context, $settings;
global $options, $sourcedir, $user_info, $board_info, $topic, $board;
global $attachments, $messages_request, $topicinfo, $language, $smcFunc;

// What are you gonna display if these are empty?!
if (empty($topic))
fatal_lang_error('no_board', false);


Multidimensional array example:
Add after above code:

$myTopics = array(1 => 'http://example.com/mypage1', 3 => 'http://example.com/mypage2');
$queryTopic = !empty($topic) ? (int)$topic : 0;

if (in_array($queryTopic, array_keys($myTopics)))
redirectexit($myTopics[$queryTopic]);

 
  Please read my post properly as I am instructing to only use one of the above examples.

Regards.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Advertisement: