1

I can't get my query string to work..please help... I have the following url: http://betatest.bracknell-forest.gov.uk/help?fb_action_ids=372043216205703&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582

(sorry but the page will be unavailable as it is a test internal domain link)

I want the following url: http://betatest.bracknell-forest.gov.uk/help

I get a browser message saying 'The system cannot find the file specified.' I know it is because I already have a mod rewrite to remove the .htm from the page name to return clean urls but I don't know what I need to do to accept a clean url and return the page.
Here is the mod rewrite code I have:

RewriteRule ^/([\w]+)$ /$1.htm [I,L] #Any bare URL will get rewritten to a URL with .htm appended
RedirectRule ^/(.+)\.(htm)$       http://betatest.bracknell-forest.gov.uk/$1 [R=301]

RewriteCond %{QUERY_STRING} ^fb_action_ids=(.)$ #if the query string contains fb_action_ids
RewriteCond %{QUERY_STRING} !="" #if there is a query string
RewriteRule ^(.*) $1? [R=301,L]

I think it is because I am using R=301 twice but do not know what I need to use as an alternative.

If I append .htm from help?fb_action_ids.... to help.htm?fb_action_ids.... this returns the required page fine but I need to return the page name for the non appended url.

Many thanks for any help in advance.

user905752
  • 31
  • 5

2 Answers2

0

OK after looking at the iirf help pages, the following strips all query strings and presents clean urls:

RewriteRule ^/(.+)\?(.+)&(.+)\.(htm)$  /$1    
RewriteRule ^/(.+)\?(.+)$       http://betatest.bracknell-forest.gov.uk/$1 [R=301]

# Any bare URL will get rewritten to a URL with .htm appended
RewriteRule ^/([\w]+)$ /$1.htm [I,L]
RedirectRule ^/(.+)\.(htm)$       http://betatest.bracknell-forest.gov.uk/$1 [R=301]

iirf requires some understanding of regex and there appear to be subtle differences between it and mod_rewite. Many thanks ofr all help given.

user905752
  • 31
  • 5
-1

These two lines will do. I've tested.

RewriteCond %{QUERY_STRING} fb_action_ids
RewriteRule ^(.*)$ $1? [R=301]

URLs with format like this: "abc?fb_action_ids......" will be redirected to "abc.htm" if you have abc.htm.

However, you can turn off MultiView in http.conf and if will be redirected to exact "abc" file.

benck
  • 2,034
  • 1
  • 22
  • 31
  • Many thanks for your reply - I was beginning to think there was no one out there...I need this to work not only for help.htm but for the whole site. so I need a redirect that works for pagename.htm where pagename is the name of the page so...http://betatest.bracknell-forest.gov.uk/pagename?fb_action_ids=372043216205703&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582 becomes http://betatest.bracknell-forest.gov.uk/pagename or http://betatest.bracknell-forest.gov.uk/pagename.htm - thanks again for the response – user905752 Oct 09 '12 at 20:34
  • OK, I've edited the above answer. It works for me but I don't know who gave me a minus one. – benck Oct 10 '12 at 04:08
  • Hi benck. I tried the above and got the following in message in Firefox:The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete. I notice that the url has changes to http://betatest.bracknell-forest.gov.uk/help?fb_action_ids=372043216205703&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582???????????????????? - adding the ? symbol which I think it is getting from $1? - Not sure if it makes any difference but I am using iirf in IIS6 on a Windows Server. – user905752 Oct 11 '12 at 10:00
  • How would it be if removing "?"? I tested on apache and it's fine. – benck Oct 11 '12 at 11:19
  • I just tried without the ? and it get the same Firefox message without the ?????????????? in the url – user905752 Oct 12 '12 at 10:39
  • Hi benck - I have spent the afternoon looking at discussions for the iirf solution we are using (http://iirf.codeplex.com/). There are differences between this and mod_rewrite that I think is the readon why the redirects work for you and not for me. I have posted on their discussion boards and will let you know what comes back and hopefully a solution. – user905752 Oct 14 '12 at 17:29