CodeIgniter Forums
.htaccess multiple redirects - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: .htaccess multiple redirects (/showthread.php?tid=16102)



.htaccess multiple redirects - El Forum - 02-24-2009

[eluser]Adam Griffiths[/eluser]
Hey guys,

I'm busy re-building my blog and I need some help with .htaccess.

Basically I'm using wordpress and need to redirect the following urls:

www.programmersvoice.com/articles/ -> www.programmersvoice.com/tag/articles/
www.programmersvoice.com/tutorials/ -> www.programmersvoice.com/tag/tutorials/

I tried it a few ways and none of them worked, so I came here!

I already have a .htacces file...

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteRule ^/tutorials/$ /tag/tutorial
RewriteRule ^/articals/$ /tag/article
</IfModule>

Can anybody see what I'm doing wrong?

If I go to www.programmersvoice.com/tag/tutorial/ I get the page I'm looking for, but when I just go to www.programmersvoice.com/tutorials/ I get a 404. The same happens for articles.

Any ideas?


.htaccess multiple redirects - El Forum - 02-24-2009

[eluser]fesweb[/eluser]
You need to put those redirects BEFORE your rewrite stuff.

Something like:
Code:
RedirectMatch ^/articles(.*) http://www.programmersvoice.com/tag/articles$1
RedirectMatch ^/tutorials(.*) http://www.programmersvoice.com/tag/tutorials$1

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>



.htaccess multiple redirects - El Forum - 02-24-2009

[eluser]Adam Griffiths[/eluser]
Thanks for replying but that's not what I'm trying to acheive.

The way your version works redirects /tutorials to tag/tutorial - but I really want it to do that without changing the URL. I tried tinkering with the version you gave me but it still just wouldn't work.


.htaccess multiple redirects - El Forum - 02-24-2009

[eluser]fesweb[/eluser]
In that case, you should be using routes, shouldn't you?

Something like this...?
Code:
$route['articles'] = "tags/articles";
$route['articles/:any'] = "tags/articles/$1";



.htaccess multiple redirects - El Forum - 02-24-2009

[eluser]Adam Griffiths[/eluser]
Yes but in this case I'm using wordpress, so there's no way of doing this easily without .htaccess.


.htaccess multiple redirects - El Forum - 02-24-2009

[eluser]fesweb[/eluser]
Plus, if you route it that way, I think your code would then need to incorporate the rerouted uri info
Code:
// this
$this->uri->segment(n)
// becomes this
$this->uri->rsegment(n)



.htaccess multiple redirects - El Forum - 02-24-2009

[eluser]simshaun[/eluser]
Try
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteRule ^tutorials/$ /tag/tutorial [NC]
RewriteRule ^articals/$ /tag/article [NC]
</IfModule>