Forum Moderators: phranque

Message Too Old, No Replies

htaccess with parameters

used a query string but still does not redirect

         

crunchyroll

10:15 am on Jun 30, 2012 (gmt 0)

10+ Year Member



So basically I used this


RewriteCond %{QUERY_STRING} ^page=services$
RewriteRule ^default.html/$ http://www.example.com/services/? [L,R=301]

However, I could not figure out why it will still not redirect.

I have about 20 others using this parameter but are pretty much the same.

page=contact
page=about
etc.

I assume by figuring out the first one, that I would just create the RewriteCond/RewriteRule for the next 19 of them?

g1smd

5:32 pm on Jun 30, 2012 (gmt 0)

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



Redirecting, or not, depends on exactly what the requested URL looked like.

^page=services$
and
^default.html/$
are very specific patterns and must exactly match otherwise the request will not redirected.

If the new page name is the same as the old parameter in each case, then one rule might cover all of the URLs.

lucy24

6:56 pm on Jun 30, 2012 (gmt 0)

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



You may have too many anchors.

^page=services$

and similar will work if you only have one parameter-- and in that case, paradoxically, you wouldn't need the anchors at all. Unless you want to redirect only the pages that have just that one parameter, and not the ones where the "page=" parameter is preceded or followed by others.

Is your page really called

default.html/

with a directory slash after the html? And, come to think of it, have you got html with queries? Both of those are a bit unusual.

The Rule-plus-condition is correctly written except that you forgot to escape the . in the pattern. If you fine-tune the anchors to fit the names and queries it should all slip into place.

I have about 20 others using this parameter but are pretty much the same.

page=contact
page=about

If they're that similar, you probably won't need 20 separate rules.

RewriteCond %{QUERY_STRING} page=(services|contact|about)\b
RewriteRule ^default\.html http://www.example.com/%1/? [R=301,L]

Note the %1 instead of the more common $1 because your capture came from a Condition. Don't quote me on the \b --can't remember for sure if you can use it in a RewriteCond. Here it acts as shorthand for (&|$) to ensure that you're only picking up exact words that come with corresponding pseudo-pages. That's assuming you don't have queries named, er, "rampage=" or "equipage=" or "stoppage=" or...

Hm. I do believe I know someone who might really have an "equipage" query ;)

crunchyroll

1:53 am on Jul 1, 2012 (gmt 0)

10+ Year Member



The default.html I believe was a "shell" url because it was created which inserted into the site as an xml, which then produced those results with the parameters.

I have a better idea now on how I may be able to fix this.

I appreciate the both in being able to provide detailed information and grateful in having you guys taking a look at my thread.

Thanks!

g1smd

7:00 am on Jul 1, 2012 (gmt 0)

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



What was the requested URL that was not redirected?

Use example.com in this forum to suppress the URL auto-linking feature.

crunchyroll

5:13 am on Jul 2, 2012 (gmt 0)

10+ Year Member



Originally, I was trying to just use the above methods, which still didn't end up working. The site is now using a wordpress and tried installing a redirection plugin to make things easier on my end. However, with the plugin installed, the problem still existed where it would not redirect and show the hosting companies landing page of something.

I then tried testing a "dummy" url i.e. - example.com/test.html?id=1000 to example.com/services

This actually worked. So, I'm trying to determine if it's something else that's causing the url's not to redirect with those specific parameters.

example.com/default.html itself doesn't actually land on a page. Maybe this piece of information can better determine why it's having the problem.

g1smd

6:44 am on Jul 2, 2012 (gmt 0)

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



What was the requested URL that was not redirected when you tried the orignal rule?

Use example.com in this forum to suppress the URL auto-linking feature.

crunchyroll

7:04 am on Jul 2, 2012 (gmt 0)

10+ Year Member



This is the requested url: http://www.example.com/services/ (it is seo rewritten)

crunchyroll

2:04 am on Jul 4, 2012 (gmt 0)

10+ Year Member



From what Lucy24 explained, it seemed to make sense:

RewriteCond %{QUERY_STRING} page=(services|contact|about)\b
RewriteRule ^default\.html http://www.example.com/%1/? [R=301,L]


However, with (servics|contact|about) in there, and then the 2nd rule, it will not go to the correct corresponding pages.

RewriteCond %{QUERY_STRING} ^page=services$ [NC]
RewriteRule ^default\.html$ /services/? [R=301,NE,NC,L]

So far I can only come up with having to write about 15-20 rules per page request. i. e -


RewriteCond %{QUERY_STRING} ^page=services$ [NC]
RewriteRule ^default\.html$ /services/? [R=301,NE,NC,L]


RewriteCond %{QUERY_STRING} ^page=about$ [NC]
RewriteRule ^default\.html$ /contact/? [R=301,NE,NC,L]


RewriteCond %{QUERY_STRING} ^page=contact$ [NC]
RewriteRule ^default\.html$ /contact/? [R=301,NE,NC,L]

and so on. Unless I'm missing something as to how Lucy's will redirect it to the correct paths on the RewriteRule where it will know how to direct it to the correct locations based on ^default\.html http://www.example.com/%1/?

g1smd

6:49 am on Jul 4, 2012 (gmt 0)

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



This is the requested url: http://www.example.com/services/


Uh. have you got your redirects and rewrites backwards?

For the redirects we have been discussing, I was expecting the requested URL to look something like:
www.example.com/default.html?page=services

crunchyroll

7:27 am on Jul 4, 2012 (gmt 0)

10+ Year Member



Sorry misunderstood,

www.example.com/default.html?page=services that would be the requested url.

I thought requested url meant, what url I was trying to request after the redirect.

lucy24

8:11 am on Jul 4, 2012 (gmt 0)

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



If there is a redirect, there will be two requests. The one the browser sent in initially, and the second one after your rule says "Go down the block, around the corner and knock on the back door". I specify "browser" because the human user generally has no control over the redirect; they just go where the browser sends them. For the server, each new request is completely independent. It doesn't matter that you were just there two nanoseconds ago asking for a different URL.

If there is a rewrite, there will be one request, even if two locations are involved. First is what the browser asked for, and second is where the content really lives. The browser doesn't know that this is happening, but the server does. So {THE_REQUEST} is only meaningful when the Rule involves a Rewrite.