Rewrite a portion of URL

Posted on 2013-06-07
Medium Priority
Last Modified: 2013-06-17
I need help rewriting a URL, please.
Here are 3 examples of the wrong URL.  I think I have 10 being indexed by google, and I would like them to point to the correct location.


I need them to redirect to these paths (and up to 10 variations of the ending).

Please note I already have code like this in .htaccss, which works for me
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ view_profile.php?mem_id=$1

# Make all requests have the www. in them
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

Open in new window

I also have this code which is working well for me too, in .htaccss

#  http://www.seomoz.org/learn-seo/redirection
#  http://perishablepress.com/case-insensitive-redirectmatch/

#  http://www.mydomain.com/view_profile.php/WWW.MYsPACE.COM/view_profile.php?mem_id=95201
#  http://www.mydomain.com/view_profile.php/WWW.MYsPACE.COM/shared_layouts.php?mem_id=95201
#  http://www.mydomain.com/view_profile.php/WWW.mYSpACE.cOM/shared_videos.php?mem_id=95201
#  http://www.mydomain.com/view_profile.php/WWw.MySPACE.COM/send_message.php?mem_id=95201
RedirectMatch 301 (?i)/view_profile.php/WWW.MYSPACE.COM/(.*)       http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/MYSPACE.COM/(.*)           http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/www.facebook.com/(.*)      http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/facebook.com/(.*)          http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/www.vampirefreaks.com/(.*) http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/vampirefreaks.com/(.*)     http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/www.twitter.com/(.*)       http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/twitter.com/(.*)           http://www.mydomain.com/$1
RedirectMatch 301 (?i)/view_profile.php/www....com/(.*)            http://www.mydomain.com/$1

#  http://www.mydomain.com/view_profile.php/kyhlgoesboom.tumblr.com/rank_band.php
RedirectMatch 301 (?i)/view_profile.php/kyhlgoesboom.tumblr.com/(.*) http://www.mydomain.com/$1

#  http://www.mydomain.com/view_profile.php/subscribe_blog.php
#  http://www.mydomain.com/view_profile.php/block_user.php
#  http://www.mydomain.com/view_profile.php/view_mem_blog.php
RedirectMatch 301 (?i)/view_profile.php/(.*)       http://www.mydomain.com/$1

#  http://www.mydomain.com/statusnotifications.php/login.php
RedirectMatch 301 (?i)/statusnotifications.php/login.php  http://www.mydomain.com/statusnotifications.php

Open in new window

The key is that /twitter.com/ seems be incorrectly inserted in my path and I need to redirect to the correct path.

Thank you.
Question by:U_S_A
  • 2
LVL 27

Expert Comment

ID: 39231134
you do not seem to be asking a question there

can you please try and be explicit regarding what you expect and what actually happens ?

Author Comment

ID: 39231202
How do I redirect requests for http://www.mydomain.com/twitter.com/blogpublic.php to http://www.mydomain.com/blogpublic.php 

How do I redirect requests for http://www.mydomain.com/twitter.com/boyandgirls.php to http://www.mydomain.com/boyandgirls.php 

How do I redirect requests for http://www.mydomain.com/twitter.com/band.php to http://www.mydomain.com/band.php
LVL 27

Accepted Solution

skullnobrains earned 2000 total points
ID: 39231229
RewriteRule http://www.mydomain.com/twitter.com/(blogpublic.php|boyandgirls.php|band.php) http://www.mydomain.com/$1

or rather

RewriteRule /twitter.com/(.*) /$1

this should work also using redirectmatch

if you need more help, try and state
- this is what i type in my browser
- this is where i expect to be redirected
- this is where i end up

do the other redirections work ?
what shows in the log ? did you activate the rewrite log ? verbose ?

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This installment of Make It Better gives Media Temple customers the latest news, plugins, and tutorials to make their Grid shared hosting experience that much smoother.
Cron is one of the most popular and basic utilities found on Unix systems. Combined with other tools, cron makes it exceptionally easy to automate a broad range of tasks on your server.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

600 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