Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

apache mod rewrite to do 301 redirects with .htaccess

Posted on 2008-10-05
3
Medium Priority
?
811 Views
Last Modified: 2012-05-05
I rebuilt my entire site from scratch and need to redirect all the old URL's to new ones. Unfortunately they are all over the place so the solution seems to use mod_rewrite with .htaccess.  I know it can be done but I am having trouble getting the syntax to work. 500 points if you help me.

Here are some URL's I need to redirect. For each number there are usually 50 corresponding numbers.
so for the first one feedid=6 there is also a feedid=1, feedid=2, feedid=3 all the way to 50 or so.

Podcast feeds
from
http://www.domain.com/index.php?module=CTV&action=viewRss&feedid=6
to
http://www.domain.com/podcasts/rss/podcast/6

Podcast subscribe page
from
http://www.domain.com/index.php?module=CTV&action=subscribe&id=7
to
http://www.domain.com/podcasts/details/7

Channel feeds
from
http://www.domain.com/index.php?module=CTV&action=channel&cid=11
to
http://www.domain.com/channels/details/video/11

External channel feeds
from
http://www.domain.com/index.php?module=ctv&action=mediaCenter&cid=21
to
http://www.domain.com/channels/details/video/21

Specific Random URL to change
from
http://www.domain.com/index.php?module=CTV&action=mediaCenterPlayer&id=2138
to
http://www.domain.com/channels/details/video/21

Here is my existing .htaccess and it is working well.

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_URI}  !(^/crossdomain.xml)
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
   rewritecond %{http_host} ^domain.com [nc]
   rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
   AddType application/x-javascript .js
   AddType      text/css .css
</IfModule>

I am using apache 2.2.3 on Centos 5
Please be specific and you get 500 points!
0
Comment
Question by:toben88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:toben88
ID: 22647207
Oops for the last one I meant
http://www.domain.com/index.php?module=ctv&action=mediaCenter&cid=21
to
http://wwwdomain.com/channels/details/video/21/mediapage
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 22647552
The last one from your 2nd post is the same original url like the 4th one. May be you ment mediaCenterPlayer? If you'd like to exclude /crossdomain.xml, you've to do that for your 2nd rule, because the 1st one will never match a request like /crossdomain.xml.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^module=CTV&action=viewRss&feedid=([0-9]+) [NC]
RewriteRule ^index\.php$ /podcasts/rss/podcast/%1? [R=301,L]
RewriteCond %{QUERY_STRING} ^module=CTV&action=subscribe&id=([0-9]+) [NC]
RewriteRule ^index\.php$ /podcasts/details/%1? [R=301,L]
RewriteCond %{QUERY_STRING} ^module=CTV&action=(?:mediaCenter|channel)&cid=([0-9]+) [NC]
RewriteRule ^index\.php$ /channels/details/video/%1? [R=301,L]
RewriteCond %{QUERY_STRING} ^module=CTV&action=mediaCenterPlayer&id=([0-9]+) [NC]
RewriteRule ^index\.php$ /channels/details/video/%1/mediapage? [R=301,L]
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
RewriteRule    ^$ app/webroot/    [L]
RewriteCond %{REQUEST_URI}  !=/crossdomain.xml
RewriteRule    (.*) app/webroot/$1 [L]
 
AddType application/x-javascript .js
AddType      text/css .css

Open in new window

0
 

Author Comment

by:toben88
ID: 22647571
found the solution here http://www.webhostgear.com/109.html
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question