On scratch.mit.edu, they use scratch.mit.edu/projects/projectID to display dynamic pages. I am working on a Scratch redesign and am wondering how to do this without doing something like scratchredesign.com/projects?id=382. And if you don't know how to not use ?=, how would I use it?
Basically, how can I make a website when if you go to scratchredesign.com/projects/352 it will show an embed of a Scratch project with the ID of 352, and this will work for any ID like scratchredesign.com/projects/4019271 or scratchredesign.com/projects/53234.
(I know you use avascript, I don't know if PHP though.)
You can use .htaccess mod_rewrite if you are running on apache or Create NGINX Rewrite Rules if on Nginx
Basically, if you are accessing the site's URLs like scratchredesign.com/projects/352, then you can try setting the iframe source according to window.location.pathname which would return "/projects/352" as a string for you to use. You can then easily set the src attribute for the iframe dynamically with a script at the bottom of the body.
The iframe:
<iframe name="site" id="site" height="900" width="750"></iframe>
The script at the end of the body, say loadIframe.js:
document.getElementById("site").src = "http://scratch.mit.edu" + window.location.pathname;
Related
can any body help me I want to change this code to thymeleaf ?
You shouldn't need ${contextRoot} anymore.
<a th:href="#{/show/category/{id}(id=${category.id})}"></a>
Sometimes it is a good practise to use a variable that stores the root-location. Think of a service that runs e.g. on localhost port 8080 BUT is accessible from the web over nginx behind the URL me.com/myService/ (port 80). In this use case # or contextRoot produces dead-links for end users since Thymeleaf doesn't know anything about that. My solution is to store e.g. "me.com/myService/" in the application properties and add this attribute by default to the model and build links like:
<a th:href="|${myRoot}/show/category/${category.id}|"></a>
If you don't need to handle things like that go with Metroids' answer, it's a good answer.
In my work we use a CMS, and I'm not entirely sure how everything is set up, but I'm having issues using anchors in my links. For example, when I have a link to another portion of the site and I try to append an anchor, such as mysite.com#video-anchor, the url inside of the <a></a> tags gets appended with UTM tags: "mysite.com/utm_campaign=...", and the #video-anchor just doesn't show up in the final URL. The result is just linking to the page, but without scrolling to the anchor that I specified. Any help?
You should use the #anchor parameter at the end, with the UTM after the URL, like this
www.yousite.com/page?utm_source=XXX&utm_medium=XXX&utm_campaign=XXX#video-anchor
This sounds like an issue with the CMS rather than anything to do with Google Analytics. I would contact support for the CMS, or edit your question title nad tag to include the name of the CMS.
Anchors don't work as they usually do when you add utm's to a URL. In fact, they break the UTM altogether. Make sure you're adding the anchor to the end of the UTM query string if you want it to work. This Webmasters post should help:
https://webmasters.stackexchange.com/q/35413/13067
I'm using resource tags for grails resource plugin to set the src of an image.
src="${resource(dir:'images',file:'bla.png')}"
This works great and takes care of whether to use http or https behind the scenes for me. The problem is I want to be able to preload these images.
I used to do something like this is JS.
$(['images/bla.png','images/bla2.png']).each(function(){
$('<img/>')[0].src = this;
});
The problem with the above is it's not using any resource tag it defaults to loading them as http and not https.
Anyone know a way around this. Or how I might preload them.
The simplest way is to use a variable in your GSP to store the images that need to be preloaded and have your javascript read that variable. For example:
GSP
var preload_images = [];
preload_images.push("${resource(dir:'images',file:'bla.png')}");
preload_images.push("${resource(dir:'images',file:'foo.png')}");
Javascript
$(preload_images).each(function(){
$('<img/>')[0].src = this;
});
Is it possible to redirect URL in to another URL without showing the new URL?
eg:
When users go to www.sample1.com/page1.html , it should show www.sample2.com/page2.html . But URL needs to be showing like it belongs to www.sample1.com , or something like this www.subdomain.sample1.com/blah.html.
I need to host some pages for another domain , but those pages should look like they belong to that domain or to a subdomain of that domain.
Using an iframe is not an option in my circumstances,any other suggestions are welcome.
The easiest is probably to use mod_proxy to display all the sample2.com pages in a sub-context:
ProxyPass /sample2 http://www.sample2.com
Thus, sample2.com/page2.html would display as sample1.com/sample2/page2.html.
Otherwise mod_rewrite may be of use as well, specifically the proxy|P flag.
Hope that helps.
I created a sitecore year/month/day folder structure in the content tree, when i view each article under the folder node, the url could be http://local/landing/year/month/day/article1.aspx, how could I make the url like this: http://local/landing/article1.aspx?
just remove the year/month/day structure in the url.
Is there some function in sitecore like remove or hide special templates in the frontend url ?
Any help , Thanks .
You can do it in 2 ways:
Use IIS 7 Url rewrite module to change the url. This way the url will be rewritten before it gets to sitecore and you don't need to change any code. You can find more info at the iis website
You can create a custom Item resolver and add it to the RequestBegin sitecore pipeline. Alex Shyba wrote about it here.
It sounds like you may have thousands of these items, but even so, you may want to use the built in functionality of Sitecore and consider creating aliases for each of these items. Programmatically creating an the alias on an ItemSaved event or ItemCreated is probably easiest.
As #marto and #seth have said, you can use URL rewriting or aliases to solve this.
There is, however, a drawback to doing this, irrespective of how you choose to do it.
If you have very many items (your structure makes it sound like you may do) then either method will require that the URL is unique. Removing the date structure from the URL means that all items in your landing section will require unique URLs (whether inherited from their item names or by some other means). This can impact on SEO for your site, as authors may have difficulty finding an unused name that is also human readable and good for SEO. It's unlikely you want to use ugly GUIDs in your URLs.
2 options
Change Bucket configuration and the set the required folder structure, bucket configuration can be found in Sitecore.Buckets.config file
Extend GetFromRouteValue Item Resolver and overwrite the ResolveItem() method to get the bucket item.
The default GetFromRouteValue class reference can be found in Sitecore.MVC.config file and replace this with your own customized implementation.
We have implemented with customized routing and getting the exact item if the route path matches.
Thanks,
Jisha