Forum Moderators: phranque

Message Too Old, No Replies

Pass parameters in the target URL of a Pass Through [PT] RewriteRule

Pass Through [PT] RewriteRule

         

Abhihome

3:29 pm on Aug 13, 2010 (gmt 0)

10+ Year Member



Hi,

I am trying to pass a parameter in the target URL in a Pass Through [PT]RewriteRule, but it is ignoring the parameters.

Requirement:
Rewrite www.mydomain.com/hotels.html to www.mydomain.com/index.html?type=hotel

Rule applied:
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com
RewriteCond %{REQUEST_URI} \/hotels\.html$
RewriteRule ^/hotels\.html$ /index.html?type=hotel [PT,L]

This works fine if I change [PT,L] to [R=301,L], but it changes the URL in the browser, which is not desirable.

Can you please help?

Thanks
Abhilash

jdMorgan

6:24 pm on Aug 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why are you using pass-through mode? -- what other module are you passing this URL to?

This rule by itself does not send a redirect to the browser, so some other code is forcing a redirect. That is how the address bar gets changed -- if the browser chooses to follow the redirect.

Jim

Abhihome

7:04 pm on Aug 13, 2010 (gmt 0)

10+ Year Member



Hi Jim,

I am using a Pass-through mode because, I don't want my original URL to change in the address bar.

As you said this rule (with [PT, L]) won't redirect.
What I meant to say that, if I change [PT, L] to [R=301,L], then it redirects.

When I do a pass through, it is stripping the parameter off the target URL I guess.

Thanks for your help.
Abhilash

jdMorgan

7:15 pm on Aug 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is not what the [PT] flag is for. Please review the RewriteRule flags in the mod_rewrite documentation at apache.org.

You only need:

RewriteCond %{HTTP_HOST} ^www\.mydomain\.com
RewriteRule ^/hotels\.html$ /index.html?type=hotel [QSA,L]

You don't need the redundant RewriteCond %{REQUEST_URI} directive or the [PT] flag on the rewrierule, but you *do* need the [QSA] (Query String Append) flag if you wish to retain the original query parameters passed by the client.

Jim

Abhihome

8:26 pm on Aug 13, 2010 (gmt 0)

10+ Year Member



Looks like there is something wrong at my end

Now I have the following rules in my conf

RewriteCond %{HTTP_HOST} ^www\.mydomain\.com
RewriteRule ^/hotels\.html$ /index.html?type=hotel [QSA,L]

But it (http://www.mydomain.com/hotels.html) is giving me a 404.
Should I include any modules for [QSA] to work?

I tried even by creating a physical file hotels.html at the root, but didn't help.

Let me dig some more and I'll get back to you.

In the mean time, if anything strikes, then please respond.

Thanks Jim
Abhilash

jdMorgan

2:39 am on Aug 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do be sure to re-start Apache and delete your browser cache after any change to the config. Otherwise, you'll see stale cached server responses and pages from your cache.

Jim