pass variable but not show in the url? - url

I want to pass a variable in my URL but not show it in the URL for SEO purposes
e.g www.mywebsite.com/Search?city=NYC should looks like www.mywebsite.com/Search and still be able to retrieve the value of "city" on the page.
Thanks

Simply use a POST request and you're done. However, is a common pratice to use GET request for search forms because the user can bookmark the url. Using POST, this isn't possible.

I just used Rewrite rules to accomplish this.

Related

Passing hidden params into url

I have a rails application in which I would like to generate a url based on a parameter, but for that parameter to be hidden from public view. So essentially working like a POST request but being able to be typed in like a GET request.
For example using a QR reader I could have the address as www.site.com/qr?lot_no=18007 but when a user scans the QR image it only shows www.site.com/qr but displays the results related to lot_no=18007.
Not sure if this is possible or not. But any help would be greatly appreciated.
If all you want to do is to prevent it from showing up in the address bar of the browser, you could use Rails.ajax to make the request dynamically through Javascript.
That will at least hide it from casual inspection, but there is no way to suppress the parameters from the query string on a GET completely, so anyone looking at the Networks tab in the browser (for example) would still see them.
Another alternative would be to encrypt the parameter value.
Maybe the Friendly id gem may be of help here
The following is an example of it's use is
http://example.com/states/washington
instead of:
http://example.com/states/4323454
This is not going to work with a post request as you mention though. It is a way of using a get request that would normally send an id in the params hash to retrieve existing records.
The gem can be found here https://github.com/norman/friendly_id
It is well maintained and up to date
Configure different route for public facing URL, the URL should include encrypted lot id as a path param.
routes.rb
get '/view_lot/:id' => 'QrCodesController#view_lot`, as: :public_view_lot
now in QrCodesController add action view_lot
def view_lot
encrypted_id = params[:id]
id = decrypt_it(encrypted_id)
#lot = Lot.find(id)
render "your_template"
end
in you QR code generation, pass URL to above action with encrypted id like public_view_lot_url(lot_id)

Get url of Orchard default pages

I am using orchard 1.9 and I am building a service in which I need to get current URL.
I have OrchardServices and from that I can get the URL like so:
_orchardServices.WorkContext.HttpContext.Request.Url.AbsolutePath;
This works like a charm for pages/routes that I have created but when I go to the Login or register page (/Users/Account/LogOn) the absolute URL is / and I can't find anyway to get the URL or at least any indication that I am in the LogOn or Register.
Anyone knows how I could get the full url?
If I understand what your're asking, you could use the ItemAdminLink from the ContentItemExtension class.
You will need to add references to Orchard.ContentManagement, Orchard.Mvc.Html and Orchard.Utility.Extensions, but then you will have access to the #Html and #Url helpers.
From there you will have the ability to get the link to the item using:
#Html.ItemDisplayLink((ContentItem)Model.ContentItem)
The link to the item with the Url as the title using: #Url.ItemDisplayUrl((ContentItem)Model.ContentItem)
And you should get the same for the admin area by using these:
#Html.ItemAdminLink((ContentItem)Model.ContentItem)
#Url.ItemAdminUrl((ContentItem)Model.ContentItem)
They will give you relative paths, e.g. '/blog/blog-post-1', but it sounds like you've already got a partial solution for that sorted, so it would be a matter of combining the two.
Although I'm sure there are (much) better ways of doing it, you could get the absolute URL using:
String.Format("{0}{1}", WorkContext.CurrentSite.BaseUrl, yourRelativeURL);
...but if anyone has a more elegent way of doing it then post a comment below.
Hope that helps someone.

How to change the URL in YII?

Ok, let me rephrase my question.
I have a website set up with URL in "path" format, and the api function works well.
Now I need to change only the URL of the api part in "get" format.
For example,
http://localhost/api/query/data?data=100294832
http://localhost/api/data/100294832
works.
api is a controller, data is a model. I have this in my main.conf,
array('api/view', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
How could I do this? Should I create an action in api called query, and moved view function code there?
Thanks a lot!
The URL http://localhost/api/data/100294832 is the same as http://localhost/api/data/?id=100294832 by your route rule. It will work by default.

How to map an URL having querystring parameters in urlmapping.groovy?

I am new to Grails/Groovy. Please bear with me if this is a silly question.
I am trying to map an URL having querystring parameters in urlmapping.groovy, something like,
"/rest/employees?empno=123&dept=delivery"(controller:"employees", action="emp")
The values 123 and delivery are dynamic values. In other words, this could be anything that the user can use.
Apparently this syntax is not correct. What is the right way to achieve this?
Just leave /rest/employees"(controller:"employees", action="emp") and you'll get your query parameters as params.empno and params.dept in your action
#splix answer is correct. If you want to use a restfull url, you could do something like
"/rest/employees/$empno/$dept"
instead. Otherwise just leave out the part after "?" as said. In your controller you will still get params.empno and params.dept
Read more here

Grails g:paginate tag and custom URL

I am trying to use g:paginate in a shared template where depending on the controller, url changes e.g.
For my homepage url should be : mydomain[DOT]com/news/recent/(1..n)
For search Page: www[DOT]mydomain[DOT]com/search/query/"ipad apps"/filter/this month
and my g:paginate looks like this:
g:paginate controller=${customeController} action=${customAction} total:${total}
For the first case, I was able to provide controller as 'news' and action as 'recent' and mapped url /news/recent/$offset to my controller.
But for the search page, I am not able to achieve what I want to do. I have a URL mapping defined as /search/$filter**(controller:"search",action:"fetch")
$filter can be /query/"ipad apps"/filter/thismonth/filter/something/filter/somethingelse.
I want to be able to show the url as above rather than
?query="ipad apps"&filter=thismonth&filter=something&filter=somethingelse.
I believe I can pass all the parameters in params attribute of g:paginate but that will not give me pretty URL.
What would be the best way to achieve this? Please feel free to ask questions If i missed anything.Thanks in advance.
Ok. figured this out. Hope this helps someone.
Set ${customAction} ='' and this query string 'filter/thismonth/filter/something/filter/somethingelse' was passed with 'params' alltribute.
Thanks

Resources