Forum Moderators: phranque

Message Too Old, No Replies

Rewrite to remove url's from a search engine

how to rewrite / redirect url's with a querystring

         

olaf

8:48 am on Nov 27, 2005 (gmt 0)

10+ Year Member



Hello,

I just modified my site and there are this of url's no more available;

profile.php?change_css=modern
or
news.php?offset=1&change_css=modern

The pages are still there but the "change_css" no more.

Several url's like above are indexed with google and other search engines adn I want to remove them there.

I tried a lot of things and think that this kind of rule have to be used:

RewriteEngine on
RewriteCond %{QUERY_STRING} change_css=([a-z]{4,6})

RewriteRule ^(.*)\.php$ http://www.example.com/$1.php [R=permanent,L]

This is wrong because it ends in a endless loop.

How can just remove the change_css from the url?

regards Olaf

[edited by: jdMorgan at 9:30 pm (utc) on Nov. 27, 2005]
[edit reason] example.com [/edit]

jdMorgan

4:27 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> How can just remove the change_css from the url?

It's quite tricky, and you may have to use two rules:


# Case 1: Additional parameters follow change_css
RewriteCond %{QUERY_STRING} ^(.+&)?change_css=[a-z]{4,6}&(.+)?$ [NC]
RewriteRule ^(^.)+\.php$ http://www.example.com/$1?%1%2 [R=301,L]
#
# Case 2: No more parameters follow change_css
RewriteCond %{QUERY_STRING} ^((.+)&)?change_css=[a-z]{4,6}$ [NC]
RewriteRule ^(^.)+\.php$ http://www.example.com/$1?%2 [R=301,L]

Jim

olaf

7:18 pm on Nov 27, 2005 (gmt 0)

10+ Year Member



Hello Jim,

are you sure that in this case the part of the querystring (change_css) is removed?

You told me in another thread that the http status is very important for google. I want to remove the entries from the index with this querystring. What if I send a header (410) in every page for every request with this querystring and then stop the script?

you know what I mean? or what is the best way to handle this?

regards Olaf

jdMorgan

7:34 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I suggest that you test the code...

Jim

olaf

7:58 pm on Nov 27, 2005 (gmt 0)

10+ Year Member



I used this kind of rules before :-(

noting happens...

http://www.example.com/news.php?offset=4&change_css=geel

or do I miss something?

gr. Olaf

[edited by: jdMorgan at 9:31 pm (utc) on Nov. 27, 2005]
[edit reason] example.com [/edit]

jdMorgan

9:29 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I had a couple of typos:

Options +FollowSymLinks
RewriteEngine on
#
# Case 1: Additional parameters follow change_css
RewriteCond %{QUERY_STRING} ^(.+&)?change_css=[a-z]{4,6}&(.+)?$ [NC]
RewriteRule ^([^.]+\.php)$ http://www.example.com/$1?%1%2 [R=301,L]
#
# Case 2: No more parameters follow change_css
RewriteCond %{QUERY_STRING} ^((.+)&)?change_css=[a-z]{4,6}$ [NC]
RewriteRule ^([^.]+\.php)$ http://www.example.com/$1?%2 [R=301,L]

Jim

olaf

10:32 pm on Nov 27, 2005 (gmt 0)

10+ Year Member



Thank you!

works perfect, what was the reason that the url was not rewritten?

jdMorgan

5:03 am on Nov 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because the code wasn't exactly, perfectly correct. That's the nature of this business.

The difference between the first code I posted and the correct code is in the regular-expressions pattern of the RewriteRule.

Jim

olaf

7:34 am on Nov 28, 2005 (gmt 0)

10+ Year Member



... OK I thought there was somthing about this row:

Options +FollowSymLinks

(never used it together with my rewrite rules)

gr. Olaf