Default 403 page not showing up - html

I recently set up a few new folders in my server, but I wanted to turn them and all their subfolders forbidden. So, using .htaccess, I simply used deny from all. The issue here is that it's redirecting me to my host's 404 page (which has a lot of advertisements, join us, it looks like their front page), instead of the regular 403 page.
This seems like a very trivial question, but I couldn't find the answer anywhere. How do I get everything in that folder to use the classic 403 page, being this:
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<h1>Forbidden</h1>
<p>You don't have permission to access /example/example2/exampleC/
on this server.</p>
</head>
</html>
Which changes depending on which folder I just entered. If In /example/ I have /example1/, /example2/ and /example3/, how do I make it so that if I enter /example1/, I get a 403 page that says I don't have access to /example/example1/?
This may seem a bit overly (needlessly) complicated.

let's debug step by step
for debugging please follow these steps
Rename in your DocumentRoot .htaccess to .htaccess_safe
Create a folder in DocumentRoot "test"
Insert in that folder a .htaccess with following content
RewriteEngine On
RewriteRule ^(.*)$ http://google.de [L,R=301]
Open in your Browser http://example.com/test/ [you should redirect to google]
If this works ... read more under step 5.
If not ... put this .htaccess in the DocumentRoot Folder and open in your Browser http://example.com/test/ if this doesn't run too, stop debugging. If it works, your Server isn't able to exec .htaccess in subfolders (check for that the rights of the .htaccess file on your server group, user and chmod .....
(5) Rename your .htaccess_safe back to .htaccess and change line 12 RewriteRule ^$ http://www.avatarchan.net/site/ [R=301,L] to #RewriteRule ^$ http://www.avatarchan.net/site/ [R=301,L] and try again

Related

Deployed laravel app, only homepage working

I have recently finished a website for a customer, the site works great locally. Currently only the homepage is working. However all links return a 500 server error.
This is 1and1, and I haven't heard many good things about it.
Currently I have the laravel folders for my app within a folder called webapp.
the domain name points to webapp/public.
I have also added the following line to my htaccess to get it to work
RewriteRule ^ /home.php [L]
which works for the homepage. I don't know much about the htaccess file, so I've messed around with a few other options such as
RewriteRule ^ /folios.php [L]
as well which is one of the links in my site, however this doesn't work.
My routes currently work like this
Route::get('/folios', 'AlbumsController#index');
However they return 500 server error
Change the line in the ".htaccess" file in the root folder from RewriteRule ^ index.php [L] to
RewriteRule ^ /index.php [L]
My suspicion is that you need to update the paths contained within public/index.php
Check out this article for instructions: https://medium.com/#Bohr/deploy-laravel-application-on-shared-hosting-godaddy-953758dc57ac
Did you run composer install on the server or copy out the vendor directory? You may also want to check that your htaccess file in the public directory contains the directives that are required (https://github.com/laravel/laravel/blob/master/public/.htaccess).
I did not realize that the server generated a new .htaccess file within the /webapp/ folder where I pointed the domain; I was editing the wrong .htaccess file

Pointing webserver to load .html page and not subdirectory index

So I have been searching for a few hours now and have not found the answer to my problem.
So I have a website that I was wanting to take the page extension off e.g. .html / .php etc.. and I had found that I could include the below code in the .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
I have now added that code and it works great for removing .html from my pages. However now I have come into a new problem. I have a page and directory both named 'guides' on the root of my public_html folder. Now when I enter the url 'www.mydomain.com/guides' the index of the guides directory is showing rather than the guides.html page that I am wanting to display.
I am wondering what would be the best way to get around this and make my server look for the webpage first rather than display the guides directory index.
I have been looking at RewriteRule's but it seems to be all wordpress content and does not work with my non wordpress website.
Any help would be appreciated, thanks.
The best solution is to change the name of the directory or the file to something different. RewriteRule can not rewrite a directory request to file as the directory request is first handled by mod-dir (directory module) .
If you do not want to change the name, then you can turn off DirectorySlash on your server using the following line in htaccess :
DirectorySlash off
https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryslash

Redirecting nonexistent index.html to home page in Wordpress is causing too many redirects in browser

I recently changed my website from static html to Wordpress, and in doing so I've been redirecting all of my former and nonexistent pages with my .htaccess file whenever Google shows me a crawl error. I've been successful in redirecting all crawl errors until today. My old index.html is throwing a crawl error and when I use:
Redirect 301 /index.html http://www.example.com
... I get this from my browser:
Too many redirects occurred trying to open www.example.com. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.*
I have since removed the above redirect from my .htaccess file and will just live with the crawl error if I can't get this resolved. But I'm thinking somebody knows how to solve this and if so, I'd really appreciate it if you'd let me know how.
You could experience this redirect loop if your DirectoryIndex is set to index.html (as the first option), which is likely to be the default setting on your server.
Basically, when you access a directory, eg. http://example.com/ (the root directory) then the DirectoryIndex directive tells the server which file to serve (via an internal rewrite). eg. http://example.com/index.html. This then seeds the redirect loop.
Since you are using WordPress, you could change this in .htaccess to favour index.php instead. For example, at the top of your .htaccess file:
DirectoryIndex index.php index.html
However, you could also solve this by using mod_rewrite (which is probably preferable). In fact, since WordPress already uses mod_rewrite (eg. RewriteRule directive) then you should also be using mod_rewrite for your redirects, not mod_alias (eg. Redirect directive). You should not mix redirects from both modules in .htaccess since you can easily get conflicts. Different modules execute at different times, regardless of their order in .htaccess.
By using mod_rewrite you can avoid a redirect loop by checking against THE_REQUEST. For example:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html [NC]
RewriteRule ^index\.html$ / [R=301,L]

301 redirect for html files in one directory only to Custom Post Type in Wordpress

I am struggling to get my head around an htaccess rule to redirect requests for an html file to go to a custom post. I have looked on here and in other places and nearly got there.
I want to redirect ONLY mydomain.com/profiles/.html to mydomain.com/name_profile/
So mydomain.com/profiles/smith.html to mydomain.com/name_profiles/smith. There are some 900 html files to be redirected and they are all contained in this directory. Other html files in the domain I need to leave correctly associated.
I currently have
RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/
But this redirects all html pages not just the ones in the profiles directory.
I am new at htaccess and have found several tutorials but none at a level I can understand, so any help is most welcome.
Place this rule just below RewriteEngine On line:
RewriteRule ^profiles/([^.]+)\.html$ /name_profiles/$1 [L,NC,R=301]
Use this rule:
RewriteEngine On
RewriteRule ^profiles/([^.]+)\.html/? name_profiles/$1 [DPI,L,R]
Or better, remove your RewriteMatch rules and replace with this:
RewriteEngine On
RewriteRule ^([^/]+)/([^/.]+)\.html/? $1/$2 [DPI,L,R]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html/? $1/$2/$3 [DPI,L,R]
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All

XAMPP only loads one of my pages

When I access my website using localhost/myfiles/index.html, my index file opens fine but if I want to click on the other pages/buttons, it doesn't work. The only way to open the other pages is if I do it manually by using localhost/myfiles/news.html and then only that pages works so I can't basically navigate my way around the website.
I had my website online yesterday and I know it works because I used it. I plan on making changes to my website and I need to be able to test them offline before I upload them to my online server. I just want to be able to navigate my site offline using XAMPP the same way that I would if it was uploaded on GoDaddy.
EDIT:
This is my .htaccess file
RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Any suggestions ?
Seems you have .htaccess at your root and its not working properly.
in httpd-vhosts.conf
<Directory "PATH TO YOUR PROJECT ROOT">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Or update your .htaccess file
Without seeing your system it's hard to tell what's wrong but try the following (comment answer if these didn't work WITH log error messages)
[STOP your Apache server instance. Ensure it's not running!]
1) move apache server/install to a folder that has no long file names and spaces
2) check httpd.conf in install\conf folder and look for AccessFileName. If it's .htaccess change it to a file name windows accepts (e.g. conf.htaccess)
3) double-check that your htaccess file gets read: add some uninterpretable garbage to it and start server: you should get an Error 500. If you don't, file is not getting read, re-visit httpd.conf file (if that looks OK, check if this is the only file which defines htaccess and it's location and it does at one place -within the file- only; also check if both httpd.conf and htaccess files are accessible: not encrypted, file access rights are not limited, drive/path available -and no long folder path and file names-)
STOP Apache again, then go on:
4) If you have IIS too on your system, stop it (uninstall it too if you can) from services.msc
5) Add the following to the top of your valid htaccess file:
RewriteEngine On
RewriteLog "/path/logs/rewrite.log" #make sure path is there!
RewriteLogLevel 9
6) Empty your [apache]\logs folder (if you use another folder, then that one :)
7) Check the following entries are set and correct:
Action application/x-httpd-php "c:/your-php5-path/php-cgi.exe"
LoadModule php5_module "c:/your-php5-path/php5apache2.dll"
LoadModule rewrite_module modules/mod_rewrite.so
Avoid long path names and spaces in folder names for phpX install too!
8) START apache server
You can do all the steps above or go one-by-one, your call. But at the end of the day make sure you tried everything above!
If system still blows up and you can't fix it, copy&paste error message(s) from log folder for further assistance