How to set the default website page through htaccess? - .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

Related

How to redirect non www to www for prod website

I've tried to add the item below in .htaccess(wamp64\bin\apache\apache2.4.37\conf) and enabled Use URL Rewriting in Joomla however when I try to type abc.com in search engine address bar it will still redirect me to search page instead of redirecting me to the website. I've also performed checking and confirmed that .htaccess file is readable, the webpage is work when go to https://www.abc.co m however redirection still not work. I just need the page to redirect from http://abc.co m to https://www.abc.co m Is there any other way to do it? Or I'm doing it wrongly?? Please help.
RewriteCond %{HTTP_HOST} ^abc.com [NC]
RewriteRule ^(.*)$ https://www.abc.co m/$1 [L,R=301]
The redirect itself works great. The issue is where you've put the file.
.htaccess files are meant to be in the root folder and sub-directories of your website, not in the config files for Apache. Think of them as configuration files the server will find on-the-fly as it serves up documents, not static configurations loaded when the server starts (which are found in the "conf" folder you referred to). (See https://httpd.apache.org/docs/current/howto/htaccess.html)
For WAMP, the root folder is typically a folder called "www" and is normally located at c:/wamp/www. See Where is the web server root directory in WAMP? More commonly, though, this folder is called "public_html" (such as with LAMP, XAMP, MAMP, or default Apache installs).

Redirect existing second page to non-existing url

I have a site https://sitename.com/web (example). So, full path to page is sitename.com/web/index.php. On ftp server there is folder /web which also contain second page file - index-2.php. How to avoid creating /web-2/ folder and redirect index-2.php to sitename.com/web-2 ?
Easy, create an .htaccess file inside the root folder of your site, then add the following lines to it:
RewriteEngine On
RewriteRule ^web-2$ index-2.php [QSA,L,NC]
This site might help you with htaccess:
https://www.htaccessredirect.net/
A nice tutorial on .htaccess files also below:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file

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.

.htaccess not working in subfolder

I have a couple of sites that are currently under development and I've put them under a specific subfolder for clients/co-workers to view - "http://dev.staffanestberg.com/site-name/". I've run into some problems getting the sites working with .htaccess. I can reach the index page by typing in the url for a site folder but neither img/style/js/etc linking or page rewriting works. Looking for a solution to this, Apache's "RewriteBase" seems to be the most likely one, however I can't get it to work.
Tried
RewriteBase http://dev.staffanestberg.com/site-name/
RewriteBase /site-name
What would be the correct method?
Thanks in advance,
-Staffan
mod_rewrite’s RewriteBase directive does only apply to rewrites using RewriteRule. And that does only apply for requests that are sent to the server.
But if the requested URIs are already wrong, RewriteBase doesn’t do any help. What you could try instead is the HTML element BASE that set’s the base URI for the current document.

Resources