Jump to content

Php 301 redirect from an index.php? address


janaro

Recommended Posts

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

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.

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

 

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

 

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!

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!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.