Forum Moderators: phranque

Message Too Old, No Replies

Problem rewriting two messy URLs

ReWriteRule not working

         

JackR

2:51 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



I'm having trouble dealing with two stubborn URLs that I can't fix


I need this to .410 gone : http://www.example.com/example_example_example.htm?a=g

RewriteRule ^example_example_example.htm?a=g\.html - [G]



I need this one to .310 http://www.example.com/example.html?iframe=true&width=80%&height=80%

to http://www.example.com/example.html

RewriteRule ^example.html?iframe=true&width=80%&height=80%\.html? http://www.example.com/example.html [R=301,L]



Neither rewrites are working.

lucy24

8:14 pm on Oct 26, 2011 (gmt 0)

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



Look up "query string".

JackR

9:06 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



I found this code on another thread and have modified it for the page 'zoe.html'. The erroneous thread reported in Webmaster Tools is still not being redirected though!

How do I fix this?:


# Redirect direct client script filepath requests back to friendly URL
# Additional parameters may precede, but none may follow "page=pagname"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.html\?(([^&]*(&[^&]*)*)&)?page=zoe.html\ HTTP/ [OR]
# Additional parameters must precede, and others may follow "page=pagename"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.html\?(([^&]*(&[^&]*)*)&)page=zoe.html((&[^&#\ ]*)*)\ HTTP/
RewriteRule ^index\.html$ http://www.example.com/zoe.html?%2%4 [R=301,L]

g1smd

10:50 pm on Oct 26, 2011 (gmt 0)

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



That solution is a million times overcomplicated from what you need. The clue is to test
%{QUERY_STRING}
. You'll also need to take steps to clear the query string when you redirect, otherwise it will loop.

Neither rewrites are working.
Those aren't rewrites, they are redirects.

RewriteRule can be configured either as a redirect or as a rewrite. You need to understand the difference. It is vital (and has been described more than a hundred times so far this year in this forum).

JackR

11:49 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



Okay, I removed that overcomplicated code.

Would you please be kind enough to paste the code that will 410 the first URL and 301 the second.

.htaccess + query string = Sanskrit to me!

g1smd

12:00 am on Oct 27, 2011 (gmt 0)

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



As I said, the code is in the forum more than 100 times already. You need to learn how to code this stuff so that you can maintain your code on your site. The forum charter precludes supplying cut and paste code because every server configuration is different and this forum exists to help educate not provide a free and on-demand helpdesk.

JackR

12:36 am on Oct 27, 2011 (gmt 0)

10+ Year Member



You don't think I read 10 threads after searching for '.301 redirect query string .html' first?

Of course I did.

But as you yourself have correctly pointed out, no two examples are the same.


for http://www.example.com/zoe.html?iframe=true&width=80%&height=80%


I have tried:


RewriteCond %{QUERY_STRING} ^iframe=true&width=80%&height=80%
RewriteRule ^zoe\.html$ http://www.example.com/zoe.html [L,R=301]


.. and about 20 other variations.

lucy24

4:05 am on Oct 27, 2011 (gmt 0)

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



width=80%&height=80%

Bzzt! Danger! Bzzt! Danger!

.htaccess + query string = Sanskrit to me!

Not long ago someone else in these Forums-- it may even have been you wearing a different tie-- compared htaccess to medieval Icelandic poetry. They are both perfectly good analogies. Like Sanskrit, htaccess has rules which are different from any rules you have previously learned. They have to be scrupulously followed. If you do so, you will have a thing of beauty.

If you make a mistake in Sanskrit, the worst that can happen is you will offend the gods. If you make a mistake in .htaccess, the worst that can happen is you will crash your server. Which do you think is worse?

JackR

4:20 am on Oct 27, 2011 (gmt 0)

10+ Year Member



Ha! You have a great memory Lucy!

I did indeed make that analogy back in 2008 in this post:

[webmasterworld.com ]

g1smd

6:20 am on Oct 27, 2011 (gmt 0)

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



Use the Live HTTP Headers extension for Firefox to investigate.

My guess is you'll see an infinite redirect loop because you have not removed the query string when you redirect, and therefore the new URL request matches the pattern again and is redirected again.

lucy24

6:46 am on Oct 27, 2011 (gmt 0)

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



Holy smokes, you had those unescaped % signs already in your first post and I overlooked them. They need to go to %25 (the percent-encoded version of-- wait for it-- % alone). But in the long term it would probably be much much safer if your query strings did not contain percent signs at all. They are just about the reservedest of reserved characters.

You may have forgotten that you linked to the thread containing the Icelandic poetry post not long ago [webmasterworld.com]. That's where I saw it :)