Forum Moderators: phranque

Message Too Old, No Replies

How to hide a rewrited URL in web browser

         

Tirsdag

1:51 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



Hi all,

I used mod_rewrite to redirect a static URL to a dynamic URL:

http://www.example.com/xyz
to http://www.example.com/getLoginPage.html?id=xyz

RewriteEngine on
RewriteRule ^([A-Za-z0-9]+) http://www.example.com/getLoginPage.html?id=$1 [L]

But I want that it shows only http://www.example.com/xyz in web browser after rewriting.

How can I do?
Thanx

[edited by: encyclo at 1:33 pm (utc) on Sep. 21, 2007]
[edit reason] switched to example.com [/edit]

phranque

2:11 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Tirsdag!

use the R flag to force an external redirect:

RewriteRule ^([A-Za-z0-9]+) http://www.example.com/getLoginPage.html?id=$1 [R,L]

also you should examplify your links to prevent them from being clickable...

phranque

2:20 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



sorry - i misread your original post.
i think your problem is when you supply the full url it implies an external redirect and you want an internal rewrite.
almost opposite of what i first thought.
try this instead:
RewriteRule ^([A-Za-z0-9]+) getLoginPage.html?id=$1 [L]

jdMorgan

3:19 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> i think your problem is when you supply the full url it implies an external redirect and you want an internal rewrite.

Correct. This is the documented behaviour.

Also, you can use the [NC] flag to make the grouped-character compare case-insensitive:


RewriteRule ^([a-z0-9]+)$ /getLoginPage.html?id=$1 [NC,L]

Jim

g1smd

5:59 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you want to see static URLs, then that is what you have to have in the links on the page.

When the link is clicked, the rewrite takes that URL request and silently gets the content from the corresponding internal dynamic filepath, without exposing what that filepath actually is.

Tirsdag

10:01 am on Sep 21, 2007 (gmt 0)

10+ Year Member



Hi,

It works!
Thank you all of you!

Tirsdag

11:22 am on Sep 21, 2007 (gmt 0)

10+ Year Member



Hi again,

Now I am facing another problem.

How can I detect if there exists a question mark (?) in a URL? If so the sub-string after this question mark in the URL will be removed.

For example,if I get a URL like www.company.com/getStartPage.html?customerId=1&sectionId=2 then I want that it show only www.company.com/getStartPage.html on web browser.

Thank in advanced
Tirsdag

g1smd

12:22 pm on Sep 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{THE_REQUEST} \?.*\ HTTP/ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1? [R=301,L]

The ? clears the query string.

Make sure that you don't create any redirection chain if you have multiple interacting redirect rules.

[edited by: g1smd at 12:24 pm (utc) on Sep. 21, 2007]

vincevincevince

12:24 pm on Sep 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The? clears the query string.

In my experience, the? is not required - the query string is not appended anyway. Although - I might be wrong!

g1smd

12:30 pm on Sep 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The query string is reappended unless you explicitly clear it.

Tirsdag

1:07 pm on Sep 21, 2007 (gmt 0)

10+ Year Member




RewriteCond %{THE_REQUEST} \?.*\ HTTP/ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
The? clears the query string.

Make sure that you don't create any redirection chain if you have multiple interacting redirect rules.

Thank g1smd, but it does not work!

So let me explain more clearly.

First I want to redirect
www.company.com/xyz to www.company.com/getLoginPage.html?id=xyz
but I want also that it still shows www.company.com/xyz on the web browser after the redirecting.

After xyz has logged in, the URL in the web browser will appear like
www.company.com/getStartpage.html?id=xyz&section=1&blah=2
Now I want that it shows only www.company.com/getStartpage.html in the web browser.

Please help me!

g1smd

1:17 pm on Sep 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> First I want to redirect www.company.com/xyz/ to www.company.com/getLoginPage.html?id=xyz but I want also that it still shows www.company.com/xyz on the web browser after the redirecting. <<

Terminology. What you require is NOT a redirect. You require a REWRITE. The two things are different. There have been several dozen code examples for that posted so far this month in this forum.

>> After xyz has logged in, the URL in the web browser will appear like www.company.com/getStartpage.html?id=xyz&section=1&blah=2.
Now I want that it shows only www.company.com/getStartpage.html in the web browser. <<

That again, is another simple REWRITE. The URL that you see is the URL that appears on the page, the link that is clicked.

The rewrite looks at the requested URL, translates it, and silently fetches the content from the dynamic internal filepath, without exposing what that filepath is.

Tirsdag

1:30 pm on Sep 21, 2007 (gmt 0)

10+ Year Member



Hi g1smd,

Terminology. What you require is NOT a redirect. You require a REWRITE. The two things are different. There have been several dozen code examples for that posted so far this month in this forum.

Thank you for your reply, I am new here, that is why I have some stupid questions in this forum :)

I got a solution for the first one:

RewriteRule ^([a-z0-9]+)$ /getLoginPage.html?id=$1 [NC,L]

For the second problem I did what you recommented

RewriteCond %{THE_REQUEST} \?.*\ HTTP/ [NC]
RewriteRule ^(.*)$ www.domain.com/$1? [R=301,L]

but unluckly it did not work.