?
Solved

htaccess remove parameter from querystring

Posted on 2011-05-02
5
Medium Priority
?
1,423 Views
Last Modified: 2012-05-11
Hello,
I am trying to find a simple .htaccess snippet to rewrite URLs to remove a parameter from the URL.

The text that needs to be removed is ?fb_xd_fragment=   or &fb_xd_fragment=   which is usually found at the end of the querystring.

The rest of the url and query string (if there is one) needs to be unchanged.

[ NB - This is occasionally inserted at the end of urls due to a well documented bug in Facebook like/ comments box (NB - I am aware of the workaround to this issue that Facebook recommend- please do not suggest that. I am specifically looking for an .htaccess rewrite solution here). ]

Thanks for your help.
0
Comment
Question by:dannyddd
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
dannyddd earned 0 total points
ID: 35508279
OK, I think I've answered my own question:

This appears to work:
RewriteCond %{QUERY_STRING} ^(([^&]*&+)*)fb_xd_fragment=(&+(.*))?$
RewriteRule (.*)?$ %{REQUEST_URI}?%1%4 [L,R=301]

I won't close the question just yet -

If anyone can spot any issues with this, or ways it can be optimised, please let me know.
0
 
LVL 4

Assisted Solution

by:a1j
a1j earned 2000 total points
ID: 35508375
RewriteEngine On
# remove one query parameter and keep the others
RewriteRule ^(.*/\?)(.*)fb_xd_fragment=[^\&]*\&(.*)$ $1$2$3 [L]
# remove all query string if there are no other query parameters
RewriteRule ^(.*/)\?fb_xd_fragment=[^\&]*$ $1 [L]
0
 

Author Comment

by:dannyddd
ID: 35508591
a1j,

Thanks - what is the benefit of your solution versus the one I already have?
NB - the one I have seems to work, so far.
0
 
LVL 4

Assisted Solution

by:a1j
a1j earned 2000 total points
ID: 35508644
You probably should keep yours because i didn't test mine at all. But your solution does that via redirect, i e client receives 301 redirect and makes second request.

If latency is not an issue then this is not a big deal.
0
 

Author Closing Comment

by:dannyddd
ID: 35814118
My own solution to this seems to be working well. But thanks a1j for your useful help and advice.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question