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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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