How to Route IIS to Nested Default Document - iis

I am trying host a site on xyz.domain.com in IIS, but the default document is at /admin/admin.php.
Therefore when I just enter the root domain (xyz.domain.com) I get an error.
403 - Forbidden: Access is denied.
I need to type the full path xyz.domain.com/helpspot/admin.php to load the site.
I have tried setting the default document to /helpspot/admin.php, but this isn't working properly.
I also tried re-routing the URL.
How can I direct to this document from xyz.domain.com using IIS?

Create an index.php in the webroot with the following to force redirect traffic from xyz.example.com/ to xyz.example.com/admin/ (it should use index.php automatically).
<?php
header('Location: http://xyz.example.com/admin/' , true, 301);
exit ();
?>
Also make sure index.php is in the default documents list - no path, just filename.

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)

Exclude certain directory from RewriteEngine on a Server running TYPO3

I want to develop a new website for a customer who is currently running a TYPO3 website on his server.
I'd like to exclude a subdirectory from the TYPO3 RewriteEngine (realurl?) so I have normal access to that subdirectory.
www.domain.com/dev
for example.
I have access to that site but as soon as I put a .htaccess file in that certain directory to protect it with a htpasswd. I get a TYPO3 Error:
Reason: Segment "dev" was not a keyword for a postVarSet as expected!
In .htaccess find this
# Stop rewrite processing, if we are in the typo3/ directory or any other known directory
# NOTE: Add your additional local storages here
RewriteRule (?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
and add your directory there
# Stop rewrite processing, if we are in the typo3/ directory or any other known directory
# NOTE: Add your additional local storages here
RewriteRule (?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico|dev/) - [L]
I found the solution and it was anything but straightforward.
I needed to add this line to my .htaccess in the protected subdirectory:
ErrorDocument 401 "Not authorized"
Apparently there is a conflict between URL rewriting and Basic Auths in cases just like mine. The Server writes a "401 Unauthorized" Header and looks for an existing error document based on a pre-defined path which then gets rewritten.

Use htaccess to rewrite folder.domain.com to www.domain.com/folder

I want to set up a blog on my current domain at
http://www.ashrobbins.com/folder/
and use htaccess so that it can be reached by simply going to
http://folder.ashrobbins.com
The rewrite I currently have in my .htaccess is below.
RewriteRule ^blog$ blog.php [L,NC]
But I get a page not found when I go to folder.ashrobbins.com in my browser...
You must setup ashrobbins.com in your host to serve content from a local folder, and add a 'folder' folder inside it.
And also setup folder.ashrobbins.com in your host to serve content from another local folder. As I can see, you haven't setup folder.ashrobbins.com nd therefore you receive that error.
It seems you are creating a new site and doesn't know how to do it. If it's new, just setup subdomain.ashrobbins.com and put your site on it. If there's nothing already served in ashrobbins.com/folder/ just don't mess with it.

How to set the default website page through htaccess?

I am currently setting up a website from a client on his hosting account. The website address and for some reason doesn't default to .php files (that is: index.php). If I put index.php and there is no index.html file I receive the following error:
If you feel you have reached this page in error, please contact the
web site owner: someemail#example.com If you are the web site owner,
it is possible you have reached this page because: The IP address has
changed. There has been a server misconfiguration. The site may have
been moved to a different server. If you are the owner of this website
and were not expecting to see this page, please contact your hosting
provider.
His hosting is a shared hosting on cpanel.
Use the DirectoryIndex directive in your .htaccess file
DirectoryIndex index.php
The problem was caused by my web-browser cache, as soon as I have cleared my cache it worked!
Try
DirectoryIndex index.php
if that doesn't work you might have to work around it by providing index.html like
<html><frameset rows="*"><frame src="index.php"></frameset></html>
(ofcourse more elaborate)
You can set your default page as the directory index using .htaccess file in 2 ways.
First method
DirectoryIndex yourfile.php
Above code will set 'yourfile.php' as the directory index. But this will applies to all sub folders as well and may occur '404' error for some related urls.
Second method
Use this code to set your handler file for the root directory
RewriteEngine on
RewriteRule ^$ /yourfile.php [L]
If you want to set a handler file for the sub folder, use this one
RewriteEngine on
RewriteRule ^subfolder/$ /yourfile.php [L]
enter image description here
im getting this error...
enter image description here
i found this line in index.php
how to remove this defualt page and make my website live

.htaccess to restrict access to folder

I have a php file that inherits (includes) another PHP files. All inherited files are located in one folder called "includes". I want to be able to restrict any direct access to this folder. Only PHP files within the server can communicate with the files in the "includes" folder. How can I use .htaccess to accomplish such goal?
FYI, I used the following code and it did not work
Order deny,allow
deny from all
Any help would be appreciated
If you don't have the option of actually moving the "includes" folder outside of the Document Root area, and using the include_path (i.e. you can't get to it from web), then enter
deny from all
in a .htaccess directory in that directory.
However, alternative is to use a DEFINES directive to only allow access to those include programs by specific authorised files. For example, put
<?php defined('ACCESS_ALLOWED') or die('Restricted Access'); ?>
in the top of the include files, and then put
<?php define('ACCESS_ALLOWED', 1); ?>
in the programs that are allowed to include those files.
This will prevent casual GETs to those include files from running them, and will work for any web server, not just those supporting htaccess files.
in your includes/.htaccess :
Order deny,allow
deny from all
You can actually just use an index.php and pass a 404 header using header():
header('HTTP/1.1 404 Not Found', 404);
IMO, this is better than a 403, since it's like the folder doesn't exist. As for the include files, put this line above the first include/require line of the main file:
define('INCLUDED', true);
And on every file in the include directory, put this at top most part.
if (!defined(INCLUDED)) {
header('HTTP/1.1 404 Not Found', 404);
}
You can deny direct access to the folder using the following Directives in htaccess or server.config contex :
Mod-alias based solution
Redirect 403 ^/folder/.+$
This will redirect all files and dirs of /folder/ to 403 forbidden error page.
Mod-rewrite base solution :
RewriteEngine on
RewriteRule ^/?folder/.+$ - [F]
Depending on possible other options set at a higher level you may need to use:
Satisfy all
Order deny,allow
Deny from all
I ran into this when the upper directory defined basic authentication including the line:
Satisfy any
This was preventing my deny from all to take effect because the users were authenticated.

Resources