How to redirect the visitors to another site in Middleman? - ruby

Redirecting to another site was very easy in PHP. If they wanted to redirect visitors from "www.yoursite.com/news" to "www.bbc.com"...all I had to do was make the "news" folder and create an index.php file in it and add this line:
<?php
header("Location: http://www.bbc.com/");
?>
And I was done! But I recently started working on a project written in Ruby, and having trouble to figure out how to achieve this simple task :<
This might be a very silly question, but any help will be greatly appreciated!!
UPDATE:
So found out that this project is using static site generator Middleman to build the site, that's why there is no routes.rb file. It only has config.rb. Can anyone please help me to figure out how to redirect in middleman?
2nd UPDATE:
Looks like because of Middleman, this redirecting isn't possible that simply. So I am asking this (very dumb) question: How to redirect URL in Javascript or jQuery

So finally found an easy solution to my problem :)
In order to redirect www.yoursite.com/news to www.bbc.com, first I created a news.html.erb file under my source folder (where you have your index.html.erb file). And in that file I added the following lines and wallaaahhhh!
<% content_for :body_content do %>
<script type="text/javascript">
// Javascript URL redirection
window.location.replace("http://www.bbc.com/");
</script>
<noscript>
// Using HTML refresh meta tag as a fail back in case the user has javascript disabled
<meta http-equiv="refresh" content="0;URL=http://www.bbc.com/">
</noscript>
<% end %>
One thing I should mention here is that most sites suggested
using window.location.href, because replace() does not put the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button process.
But in my case window.location.href wasn't doing the trick :(

You'll need to setup a custom route in routes.rb:
get "/news" => redirect("http://bbc.com")

Related

How to make client's audio file download rather than play?

I would like visitors to be able to download my music files, rather than have those files automatically open in their browsers' players, but I don't know how.
I have read that HTML5's download attribute is made for this, but I can't get it to work.
My site's DTD is HTML 4.01 Strict -- would that be affecting it?
The relevant markup is:
<ul>
<li>Test.wav</li>
</ul>
How can I get the audio files to download instead of playing them directly in the browser?
UPDATE:
Some stackoverflow members are trying to educate me as to how this site works. They believe that one of my subsequent discoveries (posted below) isn't an answer to the above question. In my opinion it goes deeper than an answer, because it proved that my question wasn't valid. Here's what I wrote:
Thanks to Sql Surfer and Developer90 for your help.
It turns out that the problem was me: I hadn't realized that, in order for the HTML 5 "download" attribute to work, my files had to be online! I had been testing them via local files on my own desktop!
Once uploaded, "download" did everything it was supposed to do.
As I commented (above), testing showed me that "download" works in files that are HTML 5 doctype as well as those that are HTML 4.01 (strict) doctype.
My apologies for inconveniencing you!
It depends on the browser the user is. As you said, you can add the download attr in the <a></a> html tag like this:
<ul>
<li><a href="Test.wav" download="Test.wav" download>Test.wav</a></li>
</ul>
What you may can use is the target attr. But this is to open a new tab. Example:
<ul>
<li>Test.wav</li>
</ul>
It must be the html4 that is affecting it.
2 Ideas:
A: Keep html 4.01 and use javascript to affect the
"Content-disposition".
B: Use the <!DOCTYPE html> to force html 5
As Devloper90 points out the target tag is relevant. Having no target tag is probably what you want.

Changing url link for page in processwire

I'm looking for a way to change the redirect for a page in processwire.
Logging in the admin back end I see this order page
Upon editing:
But the redirect url from header meta I guess still redirects to the previous link. I tried looking in the database and changed it there also but it still keeps it in settings somewhere.
Any ideas where this is?
Seems like you expect the page to redirect via a meta description tag. Meta description is for SEO, to tell search engines what the page is about. If your page has a meta redirect tag - which should look like
<meta http-equiv="refresh" content="0; url=http://example.com/">
it doesn't seem to be edititable via your CMS. Either change it directly in the templates, or add a field for this to the backend and add an output in the template.

Joomla 2.5 url shows two url with index.php and without

my url is http://www.clippingpathoutsource.com and it works fine but when I click to the logo of the page then the url shows http://www.clippingpathoutsource.com/index.php
Could anyone please help me?
it is difficult to identify the problem without looking at the code in the template file...
check the following:
1) In Template check index.php for below block of code
<div class="logoArea">
<a href="/index.php">
2) Instead of "/index.php" in the href attribute of the a tag put your domain name.

ColdFusion application caches switch statement

I'm not familiar with caching in coldfusion, but it seems it's doing somethnig it's not supposed to in my website.
I have only one index page, that uses a big switch statement to determin what cfm files to include, to build my website's pages. No everything works fine, I even have a default case that refers back to the homepage when trying to access a non-existing page.
When I create a new page and try to go to it but in the meantime forgetting I need to add a cfcase first, goes to the defaultcase. If I then create the needed cfcase, it should work, but it has cached the redirect of the last time, the path it followed in the switch/case, so I still get the defaultcase. Even if remove the defaulcase from the code, it still goes there.
Is there anyway to tell coldfusion to stop caching my switch/case. The rest of the content may be chached, no problem, just not the path of the switch/case..
edit 1
Here's my code:
<html>
<head>
</head>
<body>
<cfswitch expression="#attributes.fuseaction#">
<cfcase value="home">
<cfinclude template="dsp_home.cfm" />
</cfcase>
<cfcase value="admin">
<cfinclude template="admin/dsp_login.cfm" />
</cfcase>
<cfdefaultcase>
<cf_goto fuseaction="home">
</cfdefaultcase>
</cfswitch>
</body>
</html>
attributes.fuseaction is a variable that is stored in the url of the requested page, like so: http://www.domain.com/index.cfm/fuseaction/#switch/case-variable#.
cf_goto is a custom tag that gives a 301 code and redirects to the specified page where that variable is home.
When I do what I described above, the headers still give me the 301 error code and de redirect to the default case page. So I'm at a loss what it is that's being cached here.
CF doesn't cache switch/case logic, so it's a red herring to be looking at that to solve whatever your problem actually is.
Do you - by any chance - have "Trusted Cache" switched on in CFAdmin? If so, you'll need to clear it so your CFM files recompile when they're requested, and your changes will take effect.
Failing that: we need to see your code, as per Duncan's suggestion.

How can I redirect my domain to a different page or directory?

Please suggest a method other than use of .htaccess..
It really is homework-due-day today.
Theres httpd.conf (apache)
http://httpd.apache.org/docs/1.3/configuring.html
Or, forcing an "Error 301 - redirect".
Or, you could put a meta-refresh in your webpage redirecting to the new webpage.
e.g.
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com">
Or you could use javascript to force the redirect.
<script type="text/javascript">
window.location = "http://www.google.com/"
</script>
Then there are things like Reverse Proxy that could do what you wanted.
Depending on the technology and/or your access to the web server there are various options. In addition to the above you could use a server side code redirect e.g. in ASP.Net
Response.Redirect("http://www.google.co.uk")
I'm sure there are PHP and various other code alternatives to perform the same action.
You can do a client side redirect using an index.html and a META Refresh tag.
<html>
<head>
<meta http-equiv="refresh" content="0;url=http://www.mysite.com/MyDir/MyPage.html" />
</head>
</html>
http://en.wikipedia.org/wiki/Meta_refresh
Implementation-agnostic:
The following status codes can be used in a web server response:
301 Moved Permanently
302 Found
If you don't have access to a decent web server, try the Javascript
or Meta-Tag methods above.
Bonus: another implementation-specific advice, using Hunchentoot:
(redirect "http://otherhost/otherpath")

Resources