301 Redirect Causing Loop Error - coldfusion

I need to redirect my site from, say:
http://www.foo.com/index.cfm
to
http://www.foo.com
In this application, index.cfm is my default page (set in IIS). When I try a 301 redirect, I am getting a redirect loop error. The whole app is in ColdFusion. I am updating this setting in IIS on my index.cfm page. Please give some advice on this. Thanks in adv.

So in IIS your default page setup looks for index.cfm? I think you are getting the redirect loop because to the server http://www.foo.com/index.cfm is the same as http://www.foo.com.
It sounds like you are wanting to just hide the "index.cfm" from being displayed to the user?
In this case I don't think that trying to use a 301 redirect is the way to go.
You might want to take a look at IIS 7's URL rewrite feature, and look at Approach #3

Well I don't know coldfusion but you may condition the 301 header output just if the URL used to access the script index.cfm has any character extra on it (just if the request method is GET), this way you'll avoid infinite redirects. Here some pseudocode to explain myself:
if URL is not 'http://www.foo.com' and method is 'GET'
output header '301 http://www.foo.com/'

Related

I need to redirect a vanity url to a page of the same name inside a directory

A typical .htaccess redirect looks like this:
RedirectMatch 301 /old-page /directory/new-page
I am trying to redirect only a specific, root level page (which doesnt exist), to a page with the same name, but in a different directory- and am getting a loop (because apache is seeing "oh that ends in /whatever, lets redirect it again). Here's my redirect example, does this have an obvious problem?
RedirectMatch 301 /specific-page-name /directory/specific-page-name
The purpose of this is to add a UTM code to a page when it gets typed in from some physical marketing media (flyer, card, etc) to give them an easy to type url, and get analytics that let us know that they are coming to the site from a specific non-web source.

HAproxy redirect with path rewrite based on refer code

I am trying to rewrite a URL from what it is currently in HAproxy:
https://www.mywebsite.com/blog/Display.html?id=1262
to
https://blog.mywebsite.com/profile/old-1262/
Unfortunately when I use this:
http-request redirect code 302 location https://blog.mywebsite.com/profile/old-%[capture.req.uri,regsub(/blog/Display.html?id=,)]/
I get redirected to the root of the website and it appears the content of regsub is empty.
Has anyone a good idea as to the correct syntax that I am missing to get the redirect to work correctly?
Right, I was quite close. I studied the examples in the manual more closely and I came to this:
http-request set-uri https://blog.mywebsite.com/profile/old-%[query,regsub(id=,,g)]
And it gets me where I want to go.

htaccess redirect makes infinite loop - is there another way?

I need to redirect this URL (http://www.example.com/learn) to this URL (http://www.example.com/learn-it).
Problem is that it matches the rule on the redirected URL, and makes an infinite loop.
This does not work:
Redirect 301 http://www.example.com/learn http://www.example.com/learn-it
.htaccess 301 Redirect
The smoothest way to redirect your visitors is to use an .htaccess redirect. This has no delay since before a page is served to the browser the server checks first for an .htaccess file... if it sees this the old page never loads, instead visitors are sent directly to the new page.
These are a few .htaccess redirect codes that I've used that might come in handy for you. This is not a complete list by any means, but it took me ages to find how to do these so I'll save you the hassle and list them here. Oh, and please don't email me with questions about how these work, like I said, I found these with the help of others.. I have no idea in the slightest how to write this stuff and take no credit (or responsibility) for how they work.
If you're more technically minded than I am and want the information straight from the source, check the Apache Tutorial: .htaccess files for more detailed info.
Important notes about htaccess redirection
Always be sure to upload .htaccess files in ascii mode, sending it up as binary will break it (and usually make your server very, very unhappy.)
.htaccess does not work if you're on a windows server.
Make sure you triple check your changes. Clear your cache and look, test the server headers to make sure you see a 301 (that means its permanent) not a 302 (temporary) unless you are absolutely sure you really mean temporary.
Since some operating systems don't allow you to make a file without something before the "." you may need to save it as something.htaccess, some may even have to save it as htaccess.txt and change it once you've uploaded it.
Make sure your ftp program will show .htaccess files (FileZilla does and is free) It is a bit hard to edit something you can't see ;)
Double check that you're not overwriting an old one (some servers already place one there for your custom 404 pages etc.)
Make sure you replace example.com with your own sites URL ;-)
To Move a single page
Quick, easy and seamless for your visitors.
Redirect 301 /oldpage.html http://www.example.com/newpage.html
To Move an entire site
This will catch any traffic on your old site and redirect it to your index page on your new server. If you want to redirect each page to its new spot, this isn't the one for you.
Redirect 301 / http://www.example.com/
For detail explanation. How to redirect page usin .htaccess . read this
You should use RedirectMatch in order to use regex to be able to match exact URI:
RedirectMatch 301 ^/learn/?$ /learn-it
Make sure to clear your browser cache before testing this.

Django weird url call error

I have my Django app. I have a redirect URL(say a 404 page) to be redirected when no other URL matches. Now if any url is called as
mysite.com/something
I am redirected to the 404 page. But
mysite/something/
works fine.
The redirection url added to the end of all:
url(r'^.*/',theview),
When I remove the redirect url from the urls.py, the problem is cleared and the above URL works (without / at the end). Why is the error?
First of all, it would be a good idea to link to your previous post and mention you are using a hack that I gave you, because (A) it's not normal setup and (B) Someone might come up with a better idea than mine
Secondly, you're seeing this behaviour because of normal url processing. See, the urls mysite.com/something and mysite.com/something/ are not the same. To match it with django's urls, the difference would be:
url(r'^something/$')
url(r'^something$')
Since the difference is so minor, when using a normal setup, after failing to find the a url without a forward slash django's common middlewere* will automatically try to add one and test it. It's only then that it would give up and forward you to a 404 page.
However, in your setup, the catch-all url prevents the second round because it does apply to the url without the forward slash. My solution? Don't worry about it. The only reason you're using this hack is because Debug=True means a debug page instead of your custom 404 page, a problem you won't be facing when moving to a production environment
*and a big thanks to #Alasdair who pointed this out in the comments

Problem with reiterating BASE URL

I somehow messed up my htaccess file which altered my website base URL. The htaccess file is in my public-html directory. My web site URL is supposed to be: http://voidnow.org
I was trying to redirect traffic from voidnow.org to voidnow.org/community, but, I obviously messed it up, royally.
Attempts to reach that voidnow.org on the web take everyone to the following URL:
/community/http://voidnow.org/community/http:/voidnow.org/community/http:/voidnow.org/community/http:/voidnow.org/...
(that erroneous URL reiterates for hundreds of characters.)
Can someone help me with the correct htaccess command to restore my correct URL direction in my htaccess file. I tried removing the htaccess file, and it has no effect. I tried restoring the original htaccess file, with no positive result.
Thanks in advance.
David
If you were using 301 redirects then try clearing browser cache & restart (browser) .. or try another browser -- modern browsers do cache permanent redirects.
Right now your site works fine for me -- no redirect at all.