Welcome Guest, Not a member yet? Register   Sign In
ht access confusion
#1

[eluser]bugboy[/eluser]
Hi all

I've recently built a site in CI and its working great.

The thing is we're getting a load of old links back using query strings.

Now the sites structure has changed and we need to redirect 301 to these new pages.

I know how to do a simple 301 redirect using htaccess but as some of the have query strings thats not working.

this is what i have so far.

Code:
http://www.example.co.uk/about.php?page=1&item_id=1

i need that and any variation to go to

Code:
http://www.example.co.uk/about


this is what i have working so far

Code:
RewriteCond %{QUERY_STRING} ^page=(\d+)$
RewriteRule ^/about.php$ http://www.example.co.uk/about? [L,R=301]

but i can't seem to get it working with the second parameter

any help would be greatly appreciated.

Thanks Bug
#2

[eluser]TheFuzzy0ne[/eluser]
Code:
RewriteCond %{QUERY_STRING} ^page=(\d+) # Removed the trailing $ as you don't want to match to the end of the string.

As for the second line - I'm really quite confused. Just out of interest, why are you trying to convert a query string into segments? Why not just use segments to begin with?
#3

[eluser]bugboy[/eluser]
the old site used query strings

the new site uses CI's uri segments


i need to tell google or old links thoses pages don't exist and redirect them to the new sites pages. ot using the old sites query strings they are null and void now
#4

[eluser]TheFuzzy0ne[/eluser]
I think you're fighting a losing battle here. I think your best bet is to enable query strings within CodeIgniter if the incoming URI looks like a query string. Then you can add some PHP code to parse out the arguments. I think that with PHP you can make a much more dynamic solution. There will be a bit more overhead, but I think it's negligible.
#5

[eluser]Daniel Moore[/eluser]
I had an old site I converted and had a similar issue. There is a much easier way than using .htaccess.

Since the old site used an "about.php" then create a NEW about.php for the link backs to find.

Code:
<?php
  $redirect = 'http://www.example.co.uk/about/';
  header("Status: 301");
  header($redirect);
  exit;
?>

That would do what you were requesting. You could also get fancy with it. For example, I had something similar to your http://www.example.co.uk/about.php?page=1&item_id=1, except it was for a download (not an about). Which means the links could no longer find a download page. Each old download ID corresponded to the new download ID in an URI segment, so I took advantage of it.

Code:
if (isset($_GET['download']))
{
  $redirect = 'Location: http://example.com/download/'.$_GET['download'].'/';
  header("Status: 301");
  header($redirect);
  exit;
}

Of course, you get the idea. You could test for each query string variable and place them in the corresponding URI segment this way. That way, you'll have perfect redirects, and visitors won't be suddenly confused by going to the standard about instead of a specific page within it. And by making the status 301, it should inform search engines to convert their database to the new location.

Hope this helps.
#6

[eluser]bugboy[/eluser]
Thanks for the advice.

I'm using Daniel's solution its only to stop the old links from not working i'm just redirecting any call to that page to the new sites pages instead.

Cheers

Bug




Theme © iAndrew 2016 - Forum software by © MyBB