Redirect IIS's root to application root - iis

I have several applications installed on IIS:
/abc
/bcd
Now I want to redirect users coming to / to the /abc website. Since the root is not part of any application, I cannot use IIS Rewrite Module which uses redirects defined in web.config.
So I installed HTTP Redirection in IIS and enabled the following:
This works, if the user enters exactly http://example.com or http://example.com/, the server redirects to http://example.com/abc/.
However, if the user enters http://example.com/abc, the server treats the request as in the root directory, so it applies a redirection too, leading to http://example.com/abc/abc.
I also tried checking the first checkbox (Redirect all request to exact destination), but this leads to a redirection loop from http://example.com/abc to http://example.com/abc.
I want those users entering example.com/abc to stay there, and redirect users entering example.com to the /abc application. How can I do that?

To fix the redirect loop, you can add a trailing anchor link to the destination, for example: /abc/#. This prevents IIS from stripping the trailing slash and creating a redirect loop from http://example.com/abc to http://example.com/abc
Example redirect
Request URL:https://example.com/abc
Request Method:GET
Status Code:302 Redirect
Response Headers
Location:https://example.com/abc/#
Server:Microsoft-IIS/8.0
Request URL:https://example.com/abc/
Request Method:GET
Status Code:200 OK
URL rewrite module
Alternatively you can still use the URL rewrite module as discussed here even when it is for your root site and not an application. The web.config file should be present in your web root folder (typically %SystemDrive%\inetpub\wwwroot). You can also use the URL Rewrite UI in IIS Manager to add an inbound rule:
This will redirect http://example.com/ to http://example.com/abc/.
If the user enters http://example.com/xyz (and that file does not exist) they will not be redirected to /abc and will receive a 404, unlike the HTTP redirect module above.

Related

Url without www redirect to different page

I am having a issue with the redirects of my URL using Microsoft Azure Web Service.
When I am executing www.myurl.com I am going to the correct page.
If I remove the www and execute myurl.com it redirects me to a incorrect page. The page that is shown, is only avaiable through a sub domain like login.myurl.com.
I am hosting on Microsoft Azure Server.
The root of the server basically contains the index.html on which the main page should redirect. However, without the www it redirect into a folder on root, and goes to the index.php inside that folder. There are more subfolders and it doesn't go into the alphabetic first one.
- www
-- index.html (this should be called)
-- // login folder
---- index.php (this is getting called without www)

.htaccess redirect from subdirectory to another domains subdirectory accordingly

I am trying to make a redirect from my primary domain to an secondary domain, but only if the primary domain's request is to a sub directory.
The sub directory I want to redirect from is FTP, so if the user makes the following request:
http://www.site1.com/FTP/free/50b694124bd63/SaMple+PicTure.PnG
it would be transformed to
http://www.site2.com/FTP/free/50b694124bd63/SaMple+PicTure.PnG
but if the user makes a request that does not involve the FTP folder, the user will not be redirected. Like so:
http://www.site1.com or http://www.site1.com/somethingelse/
I am, however; a bit lost when it comes to making .htaccess files. What I have tried to do so far is:
# Redirect users
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^ftp(.*)$ http://site2.com/FTP/$1 [L,R=301]
</IfModule>
Any directions or samples would be great :)
No need to use the rewrite engine for simple redirects. I think you just want to use the Redirect directive:
Redirect /FTP http://www.site2.com/FTP
By default, this will result in a "temporary" redirect response (HTTP status 302). If you're sure the URL of the second site will never change, you can cause a "permanent" redirect response (HTTP status 301) by adding the permanent argument:
Redirect permanent /FTP http://www.site2.com/FTP
Also, note that the path of URLs is case-sensitive. If you want http://www.site1.com/ftp to also redirect, you will either need to add a rule with the lowercase path,
Redirect /ftp http://www.site2.com/FTP
or use mod_speling.

.htaccess - redirect if no subdomain and pass the wrong subdomain name to another page

I want to make the a redirect on .htaccess if someone put a wrong subdomain (that doesn't exist) and pass this subdomain phraze to the another page:
BAD SUBDOMAIN:
ABC.example.org
REDIRECTION:
my-page.com?validate=ABC
How can I do this?
Your subdomain must be resolved by a DNS server and if it is wrong(that doesn't exists) the browser will display error that can't find server. So, browser can't connect your server and how can .htaccess file work?

301 Redirect old site URL's in new Drupal installation

I'm looking to 301 redirect an URL from a old version of a site no longer being used to a new URL that has been created in fresh Drupal installation.
Old URL: /198/our-software/
New URL: /services/software-development/
In the .htaccess located in the root directory of Drupal I have added the following:
redirect 301 /198/our-software/ http://www.domain.com/services/software-development
The redirect is working to some extent, it sends the user to a url like below with a query string appended to the end of it, which results in a 404 error:
http://www.domain.com/services/software-development?q=198/our-software/
I have tried placing the redirect at both the start and end of the .htaccess file both result in a 404 page not found error.
Do I need to use a more complex redirect to get around Drupals URL rewrite?
NOTE: I'm using the Pathauto module.
Rather than edit the .htaccess directly, just install the Path Redirect module which has that exact functionality built in.
Note that the Path Redirect module is only available for Drupal 6 (as of 2/22/12)
I got it working with using "RewriteRule" instead, AND (important!) removing the leading slash in the source URL, so in your case:
RewriteRule 198/our-software/ http://www.domain.com/services/software-development [R=301,L]

Redirecting bad url links from external sites with .htaccess

I have two inbound links that land on 404 pages because the links are squiffy. I have tried 301'ing these links as normal but without success, I believe because of the characters used from this external URL.
Column<u>Radiators.html
is the page suggested on this external site and
Column_Radiators.html
is the actual page.
also
Bath%3Cu%3EFiller.html
on the external site and
Bath_Filler.html
on our actual website.
How can I succesfully redirect these pages?
Simply add these lines in your .htaccess
redirect 301 /Column<u>Radiators.html /index.html
redirect 301 /Bath<u>Filler.html /index.html
Note: I use index.html as the default redirection but you can use a custom 404.

Resources