rewrite just the url in .htaccess and not change parameters passed to script with get - .htaccess

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.

Related

rewrite rule remove ugly code

i have reading different post but was't able to implement on my htaccess.
i have a url when i search on the page i get this url http://doman.se/module/spsearchpro/catesearch?fc=module&module=spsearchpro&controller=catesearch&orderby=name&orderway=desc&cat_id=2%2C4%2C9%2C6%2C5%2C10%2C8%2C7%2C11%2C36%2C37%2C50%2C21%2C29%2C22%2C24%2C23%2C53%2C31%2C30%2C32%2C52%2C12%2C13%2C39%2C25%2C14%2C33%2C34%2C43%2C35%2C44%2C40%2C51%2C15%2C16%2C20%2C19%2C41%2C49%2C42%2C46%2C45%2C48%2C27%2C38%2C28%2C47%2C54%2C55%2C56&search_query=general&spr_submit_search=Search&n=30
how can i remove the numbers 2%2C4%2C9%2C6%2C5%2C10%2C8%2C7%2C11%2C36%2C37%2C50%2C21%2C29%2C22%2C24%2C23%2C53%2C31%2C30%2C32%2C52%2C12%2C13%2C39%2C25%2C14%2C33%2C34%2C43%2C35%2C44%2C40%2C51%2C15%2C16%2C20%2C19%2C41%2C49%2C42%2C46%2C45%2C48%2C27%2C38%2C28%2C47%2C54%2C55%2C56
or make the url like this
http://doman.se/search_query=general

Redirection in htaccess for the same domain

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.

.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]

IIS URL Rewrite - need help rewriting friendly urls for a forum

I'm new to using the URL Rewrite module and I'm having trouble with what I thought would be a simple URL rewrite for forum threads (using IIS 7.5)
I need to rewrite:
/forum/100/2534/friendly-title
or:
/forum/100/2534/334/comment/friendly-thread-title
to:
/forum/?forum=100&thread=2534&post=334&postType=comment
The rule that I have written (not working) is:
^forum/([1-9][0-9][0-9]*)/([1-9]*)/(([1-9]*)/(post|comment)/)?([a-zA-Z0-9-]{5,50})$
Which maps to:
/forum/?forum={R:1}&thread={R:2}&post={R:4}&postType={R:5}
I'm getting a 404 error.
It's correct that {R:4} and {R:5} are empty when you use the first URL. That's because there are no values for these fields. The RegEx still matches though so the URL will still be rewritten. Your code should properly handle empty values for the post and postType querystring parameters to display the entire thread and not just a specific comment (at least that what I assume is suppose to happen).
By the way, a more logical URL structure would be:
/forum/100/2534/friendly-thread-title/comment/334
This won't help you this this particular problem though but just on a side note.

Resources