Welcome Guest, Not a member yet? Register   Sign In
.htaccess - redirect old link to new link
#1

[eluser]dootzky[/eluser]
Hi guys,

this is my situation:

- I'm doing a remake of an existing site
- I've done everything in CI, ofcourse
- I have controller "article.php", which expects ID of the article (/base_url/article/84), and shows that article from the database

now, the tricky part:
- the "old site", had a page called "article.php", and it expected a GET parameter (there was no framework in that few-years-old code), and this is the old link google will look for: /base_url/article.php?id=84

so - is there any way that I can say to .htaccess file to redirect all hits from "article.php?id=84" to "/article/84/" ?

I did alot of reading, forum searching, but I can't find this thing I'm looking for.

So far, I've managed to do this:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|article\.php|public|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

and it works in a way. It allows me to get to the "old article.php file", and when I get there, I can redirect, but the thing is - my controller has the same name as the article.php page, so everytime I redirect it, I get an infinite loop.

here's an example. if I go to this link:

www.mysite.com/article.php?id=84
(and in that "article.php" file I just say => redirect-to-article/84)

I successfully get redirected to this link:
www.mysite.com/article/84

BUT, for some reason, when I get to CI controller (the second link), .htaccess file treats it like it's still the "old article.php file", and I get an infinite loop.

:|

is there a better way to do this other then .htaccess file?
I get the feeling that I must at least allow page access to the old 'article.php' file in .htaccess, or how else would the "google bot" get to that old page?

Thanks for your help, I hope I gave you enough info to help me out here. Smile
Cheers,
dootzky
#2

[eluser]Gavin Blair[/eluser]
You might be able to use this function : $this->input->get() in your controller to redirect to the right place.

http://ellislab.com/codeigniter/user-gui...input.html
#3

[eluser]dootzky[/eluser]
Hi Gavin! Smile

Thanks for your reply, and the idea, but I'm not sure that will work.

The thing is: if I have index.php and article.php files in the project root, and if I allow in .htaccess RewriteCond for article.php to be reachable, the "normaln CI" URL link won't work. Sad

It's pretty strange, acctually.

So, I'm not sure if I can use that $this->input->get() method, since I'm not getting to CI at all if I go to the link:
www.mysite.com/article/84

that link goes straight to "article.php" file in the root of the project, right next to "index.php" (CI main index file..).
I'm not sure if this makes any sense at all, perhaps you could make a little test in some of your projects, just to see for yourself what's my problem, if you have few more minutes of time.. :\

thanks again, I'll try to find a workaround again tommorrow, gotta crash now..
maybe I could use some info from the $_SERVER variables, to deremine the page URL or request... hmmmm.. -.-




Theme © iAndrew 2016 - Forum software by © MyBB