I've got
132&attribute%5B23%5D%5B%5D=Truffe+de+bourgogne&ajax_digitalElephantFilter=1
ending in url, and I need to check my url for some of this parameter and if yes rewrite canonical for this page, how can i do it.
Related
I need to redirect from one url to another in the same domain, domain is www.example.com
From http://www.example.com/ca/ceca/callback to http://www.example.com/es/ceca/callback
I tried this but it doesn't work.
# Redirect url to other url in the same domain
Redirect /ca/ceca/callback http://www.example.com/es/ceca/callback
Maybe it worths to mention that the url is not really loaded in a browser but it is requested by a payment system to get a response from our website.
Try the following rule
RewriteRule ^(.*)ca/(.*)$ $1/es/$2 [R]
What
^(.*)ca/(.*)$
Does is that it searches entire request url for "ca/" pattern, and since you want to preserve stuff after ca, we enclose it in braces. Braces make sure it gets stores in variables.
Next we rewrite the url as $1, everything matched by first expression in first set of braces, that is anything before ca, then we write "es" and then append stuff from second set of braces, stores in $2. The [R] flag is to send the redirect response header to client with the new url.
Hope this helps.
I'm using Ocpsoft Rewrite, to perform URL rewriting in a JSF project. I have a redirect rule, which works fine:
.addRule()
.when(Direction.isInbound().and(Path.matches("/venue/{id}")))
.perform(Redirect.temporary(context.getContextPath() +
"/protected/index.xhtml?venueID={id}"));
However, because of the redirect, this changes the URL in the navigation bar. I thought I could use a Join rule instead, but it doesn't work as i expected:
.addRule(Join.path("/venue/{venueID}").to("/protected/index.xhtml"))
.perform(Log.message(Level.INFO, "Rewrite is active!"));
I thought this rule would redirect from, for example, foo/venue/123 to foo/protected/index.xhtml?venueID=123, but I don't get the ?venueID=... parameter appended to the URL.
Anyone knows what the correct rule should look like?
Your rule looks correct. But a Join doesn't result in a redirect. Instead it forwards the request internally. This means that the URL isn't changed. So you won't "see" the parameter venueID in the URL. But you will be able to read the parameter using the standard Servlet API:
String id = HttpServletRequest.getParameter("venueID");
If you really want, you can do a Forward instead:
.addRule()
.when(Direction.isInbound().and(Path.matches("/venue/{id}")))
.perform(Forward.to("/protected/index.xhtml?venueID={id}"));
But this won't handle outbound HTML link correction like Join will!
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
I have a rule in my .htaccess file to overwrite ugly parameter urls with clean paths.
Here is an example:
RewriteRule ^landing(/)?([0-9]+)?(/)?$ landing/index.php?intPage=$2
So when someone goes to /landing/3, it would load the index.php page passing intPage parameters as 3.
Very simple.
However, I'm using techniques to trace Google Analytics referals, so I need to tack parameters onto this URL:
For example:
/landing/3?kt_type=ad&kt_st1=adwords&kt_st2=prize_a_us.en
The problem is that, I don't know how to retrieve the parameters that are tacked onto the URL, since the URL has already been overwritten and now I can't retrieve kt_type, kt_st1 etc.
Any idea on how to make it possible so I can still tack parameters to already overwritten URLs?
Use QSA flag. Change your rule to this:
RewriteRule ^landing/?([0-9]+)?/?$ landing/index.php?intPage=$1 [L,NC,QSA]
From official docs:
QSA - Appends any query string from the original request URL to any
query string created in the rewrite target
Is it possible to rewrite the URL part of a request but still pass the original request as a get parameter to php.
For example, my search url might be www.mysite.com/search/Search%20Request when the search request has been entered by the user and is multiple words, lower and upper case etc, I want to rewrite the url to all lowercase with no enocding signs etc, so the url is www.mysite.com/search/search-request but my get parameter gets passed correctly as &search=Search%20Request.
How can I rewrite just the url in .htaccess and not change the parameters I pass to my script with get.