• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.htaccess multiple redirects

#1
[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?

#2
[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>

#3
[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.

#4
[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";

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

#6
[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)

#7
[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>


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.