Help with redirect

New to mod_rewrite? This is a good place to start.

Help with redirect

Postby emo_boy » Tue Jun 03, 2008 10:36 am

Sorry for the noob question, but I have a simply redirect that I want to do with .htaccess. Wonder if someone could take a look at my code and see what's wrong.

My examples:

OLD LINK
http://www.abstractinfluence.com/forums ... p?cat_id=2

NEW LINK
http://www.abstractinfluence.com/forums ... album_id=2

My .htaccess (which is inside the /forums/ folder):
Code: Select all
RewriteEngine on
RewriteRule ^album_cat.php?cat_id=2$ /gallery/album.php?album_id=2


Thanks in advance.
Last edited by emo_boy on Tue Jun 03, 2008 2:00 pm, edited 1 time in total.
emo_boy
 
Posts: 3
Joined: Tue Jun 03, 2008 10:32 am

Postby emo_boy » Tue Jun 03, 2008 1:56 pm

I see a lot of posts using 'RewriteBase /'. Do I just have to add that line in?
emo_boy
 
Posts: 3
Joined: Tue Jun 03, 2008 10:32 am

Postby richardk » Tue Jun 03, 2008 2:52 pm

You do not need a RewriteBase.

You must match query string parameters with a RewriteCond and %{QUERY_STRING}
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?cat_id=2(&.*)?$ [NC]
RewriteRule ^album_cat\.php$ /gallery/album.php?album_id=2 [NC,R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby emo_boy » Tue Jun 03, 2008 4:55 pm

Thanks a ton! I had to add /forums/ before the second url in order to make it work.

I ended up with this and it works perfectly.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?cat_id=2(&.*)?$ [NC]
RewriteRule ^album_cat\.php$ /forums/gallery/album.php?album_id=2 [NC,R=301,L]
emo_boy
 
Posts: 3
Joined: Tue Jun 03, 2008 10:32 am

Postby oliver99 » Tue Nov 03, 2009 12:43 am

I used this solution
Code: Select all
RewriteCond %{QUERY_STRING} cat_id=(.*)
RewriteRule ^album_cat\.php(.*) ./gallery/album.php?album_id=%1

id will load automatically
oliver99
 
Posts: 3
Joined: Mon Nov 02, 2009 1:33 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 9 guests

cron