Hide query string from url without history.replaceState - .htaccess

I want to clean my URL, for example:
www.example.com/category/somepage/?gclid=adasdasda
or
www.example.com/category/somepage?msclickid=adasdasda
to be
www.example.com/category/somepage
while not loosing the gclid parameter.
I tried this but I'm losing my parameter in google analytics, I need to clean the URL without losing that said parameter. Google analytics cannot see the parameters.
if(history.replaceState)
history.replaceState({}, "", "/somepage/")
How can i remove query string from URL with htaccess?

Related

Remove question mark from URL query

Is there any way I can remove the question mark from URL using Mod_Rewrite like this?:
domain.com/controller-name?parameter/parameter/parameter
to change question mark after controller-name to slash
domain.com/controller-name/parameter/parameter/parameter
I want to add this to htaccess in PrestaShop, where I send query like this: parameter/parameter/parameter to controller.
Normal Presta URL is domain.com/index.php?controller=controller-name and I set on SEO settings friendly URL to this controller to rewrite to only controller-name so SEO friendly URL is domain.com/controller-name .
To send some parameters to this controller I can use URL like this: domain.com/controller-name?(here parameters)
In my controller I grab parameters after question mark ? and show content according to this parameters. The parameters are separated by a slash. So I want to get rid of question mark and replace it by slash to get: domain.com/controller-name/(here parameters) with parameters I want to look like this domain.com/controller-name/parameter/parameter/
When I use URL domain.com/controller-name/parameter/parameter/ shows error 404 and Presta don't see that I want content from controller-name.
I think it is achievable by mod_rewrite rule in .htaccess, but I don't know how to write rule according to this problem.
OR maybe there is a way to add something to controller or SEO configuration in Presta to work with / instead ? in query... that would be great solution...
You can use the history.pushState and history.popState to change the URL in the browser which won't cause a page reload. But the problem is that old browsers don't support this.
Alternatively, you can set the window.location.hash property to a value that contains whatever state information you need, then either use the window.onhashchange event, or for older browsers that don't support onhashchange (IE < 8, Firefox < 3.6), periodically check to see if the hash has changed (using setInterval for example) and update the page. You will also need to check the hash value on page load to set up the initial content.
If you're using jQuery there's a hashchange plugin that will use whichever method the browser supports. I'm sure there are plugins for other libraries as well.
One thing to be careful of is colliding with ids on the page, because the browser will scroll to any element with a matching id.

RewriteRule - redirect multi variable URL to multi variable URL

Our old website has a search URL structure like this:
example.com/Country/United States/Region/California/Area/Southern California/City/San Diego/Suburb/South Park/Type/House/Bedrooms/4/Bathrooms/3/
This is currently rewritten to point to the physical page:
/search/index.aspx
The parameters in the URL can be mixed up in different orders, and the URL can include one or more parameters.
We want to 301 redirect these old URLs to a new structure that is ordered in a logical way and more concise:
example.com/united-states/california/southern-california/san-diego/south-park/?type=house&bedrooms=4&bathrooms=3
example.com/united-states/california/?type=house&bedrooms=4&bathrooms=3
Is there a way with URL rewriting to interrogate the old URL, work out what parameters are existing and then write out the new URL structure?
Even if we can limit it to just the Country, Region, Area, City and Suburb, that may be good enough to at least return some results even if it's not perfect.
Also, spaces should be turned into hyphens and all text made lowercase.
I already have the RewriteRule to turn the new URL structure into a URL to point to a physical page. It's just transforming the old URL in to the new URL I need help with. I've googled endlessly and it's just beyond me!
Can anyone help? Thanks.
Since you already have the old search page with rewriting rules set up for it and which is capable of parsing all parameters you need, the easiest and most appropriate solution I see here is to issue a redirect you require from this old search page's code. Just put the code that composes new URL with all parameters needed and redirects from this page - this should be a lot easier than trying to parse all these parameters in .htaccess and combine them into the new format.

SharePoint 2013 crawl external website with querystring parameter

I need to index my company's employee manual, which is hosted on an external website. This page requires login, and supports auto-login through a query string parameter.
Like this: http://manual.externalprovider.com?token=xxxxxxxxx
When entering this URL in my content source I get no result and the following warning:
Item not crawled due to one of the following reasons: Preventive crawl
rule; Specified content source hops/depth exceeded; URL has query
string parameter; Required protocol handler not found; Preventive
robots directive. ( This item was deleted because it was excluded by a
crawl rule. )
Is it impossible to crawl content that has a query string parameter in the start addresss? Any other suggestions on how to solve this?
I think it is possible, but you need to create new crawl rule.
Go to Search Service Application -> Crawl Rules -> New crawl rule.
Then paste your starting url: http://manual.externalprovider.com/* and please check "Include all items in this path" and then "Crawl complex URLs (URLs that contain a question mark (?))".

.htaccess internal rewrite with preserving query string

i need to rewrite a url, preserve one query string for internal rewrite.
and another for display.
so this current url:
www.mysite.com/staff/teachers?id=37:john
needs to be internally rewritten to:
www.mysite.com/staff/teachers/37
not quite sure where to start, im trying this, but don't know how to access the number between "id=" and ":" to use for the rewrite
thanks for your help.
You cannot rewrite a URL "for display". All you can do is tell the browser to load a new URL. When the browser requests the new URL, the server has no way of knowing why it is being loaded (i.e. that it was the result of a previous redirect) so that new URL will need to include enough information to load the actual page.
In other words, you have to either:
include the ID in the "pretty" URL, such as www.mysite.com/staff/teachers/37-john
have your application look up the user based on their name in the internally rewritten URL, e.g. www.mysite.com/staff/teachers?lookup_name=john

301 redirect URL with query string, removing part of the beginning URL, keeping the full query at the end

I'm trying to find a redirect that will remove part of a URL (in the middle), but leaves the query string in place at the end.
I can do this fine via a single url redirect, but there are hundreds of these urls so I'm trying to find a rule that might be able to do for all of them in one fell swoop, so i don't have to make one for each and any new ones will get redirected automatically.
I'm trying to remove 'search.php' from the urls, here is an example:
www.site.com/products/search.php?rPage=/items/listing/detail_handler.jsp?code=219592&units=Feet&item_id=2624472
to redirect to:
www.site.com/products/?rPage=/items/listing/detail_handler.jsp?code=219592&units=Feet&item_id=2624472
Thanks for your time.
According to the documentation, the query string is passed through unchanged by default
RewriteRule products/search.php http://www.site.com/products/ [L,R=301]

Resources