.htaccess to redirect all domain URLs - .htaccess

I would like to redirect example.com and example.com/ALL aswell as example.com/ALL/ALL, example.com/ALL/ALL/ALL etc. to example.com/offline.html, temporary. How can I do this through .htaccess ?
ALL = whatever you type
Thank you.

Redirect 302 / http://example.com/offline.html

Don't use .htaccess for this.
http://httpd.apache.org/docs/1.3/howto/htaccess.html#when
I'd recommend a proxy server.
Shovels for digging, hoes for sowing.

you just need create an HTML file called App_offline.htm then copy this file to the root of your web application
for more details have a look at:
http://msdn.microsoft.com/en-us/library/f735abw9(VS.85).aspx

Related

redirect by file extension in htaccess

I need to redirect all calls to aspx files in a specific sub-folder of the web to the same name and path with a .php extension.
For example
/onlinehelp/default.aspx will go to /onlinehelp/default.php
/onlinehelp/stuff/junk.aspx will go to /onlinehelp/stuff/junk.php
It seems simple enough, but I can't get it to work. I thought this would work:
RedirectMatch 301 (/onlinehelp/.*)\.aspx$ http://www.mydomanin.com$1.php
What am I missing?
thank you...it is working ....now. must have been a caching problem. curse the load balancers!!! lol sorry for the trouble. I appreciate the responses
The .htaccess file is sitting in the subfolder /onlinhelp/ where I need the redirection to take place.

Setup htaccess not to redirect when hit from main site

I'm not even sure how to ask this correctly so if I am duplicating a question I apologize. How do I use my htaccess file to only redirect when someone is coming in on something other than the main site name?
Example:
I do not want redirect on www.examplesite.com
I do want to redirect on www.examplesite.com/page.php
I think this is what you're looking for:
Perform a redirection with .htaccess
The easiest and simplest way of redirecting with .htaccess is to use the Apache module mod_alias and its command Redirect. Here’s is how to make a temporary redirection with htaccess:
Redirect /page.php http://www.examplesite.com/go_to_this_page.php
Is this along the lines of what you're asking? If so, I hope it can help.
The Structure : redirect accessed-file URL-to-go-to
The code :
Redirect 301 / http://www.examplesite.com/page.php

Redirect custom URLs via htaccess

I have my own domain:
http://cesarferreira.com
and I wanna make
http://cesarferreira.com/github
point to
https://github.com/cesarferreira
Without having to make a /github/ folder with an index.html with a redirect for each page I own (facebook, twitter, pinterest, etc)
Is there a way like for example htaccess catchig *.com/github and pointing to a given static url?
Thanks a lot
If your document root serves -
http://cesarferreira.com
you can put a redirect in .htaccess like -
Redirect /github https://github.com/cesarferreira
Take a look at URL rewriter 'http://httpd.apache.org/docs/2.0/misc/rewriteguide.html'. That should be able to do everything you want and more.
As long as it is enabled in apache then you can use it in .htaccess files also.
You can use mod_alias:
Redirect 301 /github https://github.com/cesarferreira
Or if you only want github to point only to the folder:
RedirectMatch 301 ^/github https://github.com/cesarferreira
You can put that in the htaccess file of your document root.

.htaccess Redirect Directive file to directory

I'm writing a .htaccess to support a couple moved files on a site. The concept is that /filename.htm is now at /filename/index.htm and I want links to it to read just /filename/. Here is what I have:
redirect permanent /filename.htm http://www.example.com/filename/
Will this work as expected? Thanks.
Yes, your code looks good, should do the trick.

How can I redirect to a different domain without changing the URL in the address bar?

I want to redirect from:
domain1.com/photos
To:
domain2.com/photos
I want the URL in the address bar to still read:
domain1.com/photos
Is there a way to do this using only .htaccess?
Note:
My .htaccess file for domain1.com is currently completely blank.
No, there isn't a way to do this with .htaccess. Doing so would present a glaring security hole - imagine someone doing this with a bank's website!
If both are hosted on the same server, do this in your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule (.*)$ http://www.domain2.com$1 [P]
</IfModule>
If you own both domain1 and domain2, you could accomplish this through domain name forwarding. Check your domain name registrar (like godaddy.com) for the options.
No, you can not do it through htaccess file.
You could open an iframe in domain1.com/photos that shows the contents of domain2.com/photos. But then the url would never change from domain1.com/photos, even when you went to a different page in domain2.
What are you trying to do? It sounds very sketchy. Do you own both domains? Why would you want to duplicate the contents of one site at another address?
Why is this not possible? Seems like a reasonable task as long as your Apache has mod_proxy installed:
ProxyPass /photos http://domain2.com/photos/
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass
A way around it, if the page at domain.com/photos is a server side script, do an HTTP call and serve up the response.
In ColdFusion:
<cfhttp url="another.domain.com/photos">
<cfoutput>#CFHTTP.FileContent#</cfoutput>
They'll be an extra request, but it'll get you the output you want.
its impossible using htaccess file.

Resources