Solved

Cloaked Rewrite/Redirect

Posted on 2004-09-30
18
317 Views
Last Modified: 2010-03-04
Hi

I would like any user visiting http://my.domain.com/name
to be sent to http://www.mydomain.com/view.php?username=name

I currently have a mod-rewrite rule in place
RewriteEngine On
RewriteCond %{HTTP_HOST} ^my.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/view.php?username=$1 [L]

The problem is that the user sees that he was redirected to view.php. I would like the user to still see http://my.domain.com/name in the address bar. I am doing this from the server configuration not from an individual directory.

Thank you :)
0
Comment
Question by:LiquidIce911
  • 9
  • 8
18 Comments
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
I'll raise point value if someone can help out.
0
 
LVL 2

Expert Comment

by:lathwood
Comment Utility
Are you sure it redirects and doesn't cloak?

I have similar thing which works, try the following:

RewriteEngine on
RewriteRule ^/([0-9a-zA-Z]*)(/?) /view.php?username=$1 [L]

That should match any name after the initial / which contains a numbner or letter (uper or lower case). It will then take that name and send the user to view.php?username=whattheytyped without redirecting.

Neil
0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
that messes up the links on the site because it links everything to them .. how can I fix that ?
0
 
LVL 5

Expert Comment

by:mrielf
Comment Utility
what is your file structure on web page?
0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
I have the following structure:
/html/   holds the PHP files (view.php is the important one here in this case)
/html/pictures/  holds user pictures
/html/images/   holds the website graphics
0
 
LVL 5

Expert Comment

by:mrielf
Comment Utility
Use this:

        RewriteEngine on
        rewriteRule   ^/pictures/* - [L]
        rewriteRule   ^/images/* - [L]
        RewriteRule   ^/([^/]+)/$ /view.php?username=$1 [L]
        RewriteRule   ^/([^/]+)/(.*)$ /$2 [R]
0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
It doesn't work. . Notice I am sending the user from MY.domain.com/username not from www.domain.com/username
0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
I noticed you have to add the full path to it .. like /var1/domain/html/view.php?username=$1 .. it got closer to working but it still did not work fully ..
0
 
LVL 5

Expert Comment

by:mrielf
Comment Utility
Then Place this into My.domain.com section. It uses Proxy module so ensure you enable it.


        RewriteEngine on
        RewriteRule   ^/([^/]+)/$ http://www.domain.com/view.php?username=$1 [P,L]
        RewriteRule   ^/([^/]+)/(.*)$ http://www.domain.com/$2 [P,L]

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 5

Expert Comment

by:mrielf
Comment Utility
In this case

http://MY.domain.com/                          not redirected...
http://MY.domain.com/anydir/                redirected to http://www.domain.com/view.php?username=anydir
http://MY.domain.com/anydir/anyfile       redirected to http://www.domain.com/anyfile


If you want some dir on http://MY.domain.com/ not to redirected, then place this

           rewriteRule   ^/dir_not_redirected1/* - [L]
           rewriteRule   ^/dir_not_redirected2/* - [L]

right after "RewriteEngine on" row.
0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
that freezes up and does not work .. if I take out the last line it forwards the page okay but does not show the images correctly.. as soon as i add the last line it all crashes
0
 
LVL 5

Expert Comment

by:mrielf
Comment Utility
It worked for me, i checked it with your directory structure...

If the first redirect is working, then second why not (it's logicaly same as first)?

Please post some of your error log.


0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
the website links are not absolute.. they are all relative.. could this cause any problems?
0
 
LVL 5

Expert Comment

by:mrielf
Comment Utility
Please post some example...
0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
RewriteEngine on
        RewriteRule   ^/([^/]+)/$ http://www.domain.com/view.php?username=$1 [P,L]
        RewriteRule   ^/([^/]+)/(.*)$ http://www.domain.com/$2 [P,L]

when I do that it does not work .. I have to change the ^/([^/]+)/(.*)$ to ^(.*)$ for the first one and the second one too. Then it goes to the page but the pictures are all messed up. Adding the folder example like you have did not solve that problem. And the links all direct to http://my.peoplegrade.com/whatever.php .. I need them to link to the normal www path such as http://www.peoplegrade.com/whatever.php
0
 
LVL 5

Accepted Solution

by:
mrielf earned 100 total points
Comment Utility
How are the pictures included in page on www.domain.com ?

href="/pictures/anypic.jpg"
or
href="pictures/anypic.jpg"

In first case to do the thing is hard, please use the second one without the first "/"

If you do this, I think my solution will work for you...
0
 
LVL 5

Expert Comment

by:mrielf
Comment Utility
Oh, I see your problem...

But only user pictures not displayed... for exaple images/mailuser.gif and images/addfriend3.gif and all other banner background displays properly...

I will look into your page source why pictures not displayed...

If I give user pictures in browser like this: http://MY.domain.com/USER/pictures/USERxxxx.jpg then image is displayed...

Maybe there is something with javascript, but it's not sure. I'm not good at Javascript and at HTML...
0
 
LVL 1

Author Comment

by:LiquidIce911
Comment Utility
it's okay thanks for all your help .. I'll figure this part out or do direct linking
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Apache server crashes randomly 38 107
Wordpress on WAMP Server 3 Issue 15 86
IPv6 Networking 6 90
Apache / XAMPP  authorisation 10 16
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…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now