Forum Moderators: phranque
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]
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]
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§ionId=2 then I want that it show only www.company.com/getStartPage.html on web browser.
Thank in advanced
Tirsdag
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§ion=1&blah=2
Now I want that it shows only www.company.com/getStartpage.html in the web browser.
Please help me!
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§ion=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.
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.