janaro Posted June 10, 2010 Share Posted June 10, 2010 Hi, I'm new to the site and don't seem to find the subject covered. I was wondering if somebody could please help me: I have done a lot of changes to my website and need to create 301 redirects to a lot of pages. I'm new to php and I'm not sure how to redirect the following: I will explain: I need to redirect http://www.domain.com/index.php?option=com_content&task=view&id=70&Itemid=82 to a new page without messing with the new and good index.php. Is it possible to create I would do it like this? Example: <?php header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.domain.com/business/banks/l"); exit(); ?> And save as: index.php?option=com_content&task=view&id=70&Itemid=82 Please correct me if I'm wrong about any of this because I have little or no experience in coding...but the "index.php?option=com_content&task=view&id=70&Itemid=82" would never be possible right? I got to do this for at least 30 pages and I'm no even able to do 1 Thanks for any help Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/ Share on other sites More sharing options...
jonsjava Posted June 10, 2010 Share Posted June 10, 2010 So I can understand fully, you want to redirect to a different page while keeping the GET variables? If so, That should be pretty simple. Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/#findComment-1070506 Share on other sites More sharing options...
janaro Posted June 10, 2010 Author Share Posted June 10, 2010 Hi, Sorry for no explaining myself... I want to redirect a page that I had about banks (http://www.domain.com/index.php?option=com_content&task=view&id=70&Itemid=82) that no longer exists to the http://www.domain.com/business/banks/ address using a 301 php redirect. Once I know how to do the first redirect, then I will try to do the rest. Thanks for your help! You seem to be the only one interested in giving a hand. Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/#findComment-1070578 Share on other sites More sharing options...
bnovak Posted June 11, 2010 Share Posted June 11, 2010 <?php Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location:http://www.domain.com/business/banks/index.php" ); ?> one thing I figured out after a lot of swearing is that (at least on my server) you need to close the http string - IE it needs to end with the actual page, and not a folder. Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/#findComment-1070609 Share on other sites More sharing options...
janaro Posted June 11, 2010 Author Share Posted June 11, 2010 I thought it had an exit in it: <?php Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location:http://www.domain.com/business/banks/index.php" ); exit(); ?> Then I would have to save it as the oldpagename.php, but can I save it as: index.php?option=com_content&task=view&id=70&Itemid=82 Thanks again, at least you have been past the swearing stage, I still haven't be able to get to that stage yet (I'm in the crying stage). Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/#findComment-1070795 Share on other sites More sharing options...
kenrbnsn Posted June 11, 2010 Share Posted June 11, 2010 This really should be done with re-writes in your .htaccess file Ken Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/#findComment-1070798 Share on other sites More sharing options...
janaro Posted June 11, 2010 Author Share Posted June 11, 2010 Hi, .htaccess would be: RewriteEngine on rewritecond %{http_host} ^coolexample.com [nc] rewriterule ^(.*)$ http://www.coolexample.com/$1 [r=301,nc] How would I redirect the php variables to the different folders? For example, how would I get index.php?option=com_content&task=view&id=70&Itemid=82 go to /folder/subfolder ? Thanks for you .htaccess enlightment! Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/#findComment-1070848 Share on other sites More sharing options...
janaro Posted June 12, 2010 Author Share Posted June 12, 2010 I found this example for a htaccess 301 redirect: As the parameters in the URL query may have an arbitrary order, you need to use a either one RewriteCond directive for every parameter to check or for every possible permutiation. Here’s an example with a RewriteCond directive for each parameter: RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$) RewriteCond %{QUERY_STRING} ^([^&]&)*part=1(&|$) RewriteRule ^bunch\.of/unneeded/crap$ /page.php/welcome? [L,R=301] RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$) RewriteCond %{QUERY_STRING} ^([^&]&)*part=2(&|$) RewriteRule ^bunch\.of/unneeded/crap$ /page.php/prices? [L,R=301] But as you can see, this may get a mess. So a better approach might be to use a RewriteMap. The easiest would be a plain text file with key and value pairs: 1 welcome 2 prices To define your map, write the following directive in your server or virual host configuration (this directive is not allowed in per-directory context): RewriteMap examplemap txt:/path/to/file/map.txt Then you would just need one rule: RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$) RewriteCond %{QUERY_STRING} ^([^&]&)*part=([0-9]+)(&|$) RewriteRule ^bunch\.of/unneeded/crap$ /page.php/%{examplemap:%2}? [L,R=301] I'm looking to do similar but with index.php?option=com_content&task=view&id=70&Itemid=82, index.php?option=com_content&task=view&id=70&Itemid=83, index.php?option=com_content&task=view&id=70&Itemid=84... Please advise! Link to comment https://forums.phpfreaks.com/topic/204371-php-301-redirect-from-an-indexphp-address/#findComment-1071121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.