301 Re-direct for vanity url - javascript

Stumped with this one...I've got a case where we are doing something very similar to how a site like bitly would opperate.
We've got a vanity URL, say its "myurl.com/randompagename". We own the "myurl.com" but there is nothing called "randompagename" on the server. I initially suggested creating a "randompagename" and putting a JS redirect script in.
<script>
window.location.replace("http://anothersite.com/mynewpage");
</script>
Unfortunately I'm told with our hosting we don't have the ability to create pages or add scripts (sounds odd to me).
So now i'm wondering if I have no way of physically creating an end destination for the original page to house the redirect then how do I achieve this?
Would the user not just wind up on a 404 page because the vanity URL doesn't actually exist?
Edit
Does anyone know how a site like Bitly does their re-directions? That might help me better understand plausible solutions for this.

Related

JavaScript Redirect depending on the Domain (for Blogger website)

I have a blogspot blog (Blogger). And have just noticed that my posts are being scraped (illegally copied) onto another site by some low-life.
I have 2 options:
Just ignore it
Try to trick them
I would like to put a script on my blog posts that look for the domain name of my blog, and if it is not correct, to redirect the viewer to my blog.
Is this possible? Will it work?
I am hoping that the scrape method being used is just a copy-paste method, and would like to redirect anyone who visits the offending site back to me (the original content creator).
I know that they could just remove the script, but I would still like to know if it can be done. I would like to see if it works.
if (window.location.href !== "YOURSITE") window.location.href = "YOURSITE";
Should work fine if they copy the entire HTML
If they just copy the text, this won't work at all.
Getting your articles copied sucks, I hope you'll be able to resolve it.

Changing pages URLs without using route controllers

First of all, sorry for the lame question (probably). I tried to search for an answer but I'm not finding everything I need for my issue.
So... I have a bootstrap website and I am trying to change the page URLS to appear like this :
For example : www.site.com/AboutUs.html - to appear as www.site.com/about-us
I am using the pushState method for this as it follows:
var stateObj = { AboutUs: "about-us" };
history.pushState(stateObj, "About Us", "about-us");
So I get the needed URL address there (www.site.com/about-us).. so far so good. But on page refresh it throws an error stating "The requested URL /about-us was not found on this server."
If I hit the back browser button it goes to www.site.com/AboutUs.html again.(and it is supposed to go on the home page)
My question is :
What am I missing, am I supposed to make a controller and how ?
I am not using C#, I can probably use some help with PHP because I am not good at it. JavaScript / jQuery are welcomed.
Thanks in advance and sorry for the dumb question.
Happy days!
The point of pushState is to be able to say: I have modified the page with JavaScript, the new state is what you would get if you just asked the server for this URL.
You shouldn't use JavaScript for this problem at all. You just want to have a page appear at a particular URL.
You need to configure the server to serve up the content you want on the URL you want.
What am I missing, am I supposed to make a controller and how ?
You need something on the server to handle the URL /about-us.
"A controller" is something you would probably use if you were using the MVC architecture on the server … and it doesn't sound like you are.
More likely you will be wanting to use an Alias, a tool like mod_write, or simply moving the static file to a directory called about-us and renaming it index.html.

AngularJs deep linking to a specific ng-view

I followed a tutorial on angularJS with subviews using ng-views
I'm using html5Mode in my locationProvider and a nodejs backend
If I wanted to link to or hit refresh while on a specific ng-view, I could use a hashtag. So like, to explain: if my angular app lived on localhost:3000/app and I had a view at localhost:3000/app/subview, if I hit refresh my node server didn't know how to go to a specific view on the front end.
But if, on the server side, a request came through for /app/subview and I redirected to or rendered /app#/subview (with the hashtag in there), then I went to the correct ng-view on the front end. That's what I wanted. Of course, there's more than one way to skin a cat I guess, but it was working.
Now, I'm trying to do that again. But this time it's not working.
If I try to go to localhost:3000/app#/subview via a link or refresh, instead of going to the ng-view that lives at /app/subview like it did before, it's going to /app#%2Fsubview instead. And I'm ..heh .. heh.. not sure what's different. I thought I was doing everything exactly the same.
Has anyone had this problem? Does anyone know what is happening?
Edit:
I think I kind of found a workaround. If I set base href = "/app" in the head of the html document, and then respond to a request to app/subview with a redirect to app#/subview, then I can serve up app with the correct subview (only the url goes to /subview). I think this might be acceptable for me even if it's not quite ideal but OH WELL

Javascript Redirects with Pound not working in Wordpress

I have a link to my site on a very popular but now dead website. The link is incorrect, so I'd like to redirect users to the correct page when they visit. I'm using Wordpress for my content.
The problems lie in the fact that the incorrect URL that the website lists is http://www.senntenial.com/#!mysterium/cj6d . From my research, I cannot do a 301 redirect in my htaccess, since this URL has a # sign, and is client only.
So, I tried creating the following script in my header.php file.
if (window.location == 'http://www.senntenial.com/#!mysterium/cj6d'){
window.location = 'http://www.senntenial.com/mysterium/';
}
I would think this would have worked, but it doesn't. To identify the problem, I tried simply inputting window.location = 'http://www.senntenial.com/mysterium/'; Which worked correctly, meaning my problem lies in identifying the current window location.
How can I accomplish this? I assume Wordpress has a funky way of going about things with URL's to make them easier to read that may be messing with my code.
(PS, I tried WP extensions like EPS 301 redirect to no avail.)
Also, the mysterium page is static HTML, and not involved with Wordpress' CMS.
There's window.location.hash which gives the fragment part of the current URI. So something like
if(window.location.hash=="#!mysterium/cj6d"){
window.location = 'http://www.senntenial.com/mysterium/';
}
Might work. You could also use window.location.href which contains the full URI but then you need to check with and without www.

Get URL and redirect before page load

So, i have an interesting situation. I've been working on re-organizing a directory on a website. I updated old files there's about 100 of them, they are in a new location. The old files have been taken down.
The problem I have is there are probably hundreds of people that have bookmarks directly to the URL of the old files. (e.i. "wahwah.com/subSite/pdfs/something.pdf") these files are 5 years old so they need to find the new ones anyways.
So instead of having a page for each individual file, Can I have something in the directory that used to house the files to watch for that URL and redirect to the new page?
It would watch for "wahwah.com/subSite/pdfs.." and redirect. Or maybe something in the main directory of this subSite to watch for the URL to have the /pdf path in it.
I know I can grab URLs in java script but that doesn't help me unless I can do what I stated above. I'm not sure how if at all I could do it in .NET. our servers support .NET because most of our site apps were made with it but I don't deal with those. I cannot use PHP, the servers don't use it.
I'm hoping JavaScript will be able to do it somehow, but it's something i've never tried before so just thinking about it i'm not sure I can. I'm not much for using JS libraries so Im not sure what is out there i've been searching a bit though.
I found Grunt but i'm not entirely sure how it works just yet. Just looking around maybe the file filter or matchBase. or some of the Global patterns.
If you have access to server, your best option is to set up redirect in there on wahwah.com/subSite/pdfs/ directory.
How to do this depends on if you're on IIS or unix.
In asp.net, 301 redirect is fairly efficient.
if (HttpContext.Contains("http://old.aspx"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("http://www.new.aspx");
}
Or in page load you can write:
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://new.aspx");

Categories

Resources