I edited the .htaccess file on my site, and added the line
ErrorDocument 404 page-not-found.html
So when I put in example.com/pagethatdoesntexist, the screen just displays "page-not-found.html". Why does this happen?
As per Apache reference documentation, URLs can begin with a slash (/) for local web-paths (relative to the DocumentRoot), or be a full URL which the client can resolve.
So in your case, this should do the job.
ErrorDocument 404 /page-not-found.html
With no /, your webpage name will be treated as a message and printed in the browser.
Related
When I run jekyll serve, I open the site localhost:4000 in the browser. Partial pages shows 404. And the serve indicates the error "error `/' not found" .
But when open the site use 'https://username.github.io', it's just be all normal.
It's completely confused.
enter image description here
You need to change the param "baseurl" in your "_config.yml" to a path where you expect your site to be served or comment the line of "baseurl" to allow '/'
to used instead.
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]
I have a domain domain.com
And when I type domain.com/something.html/new/one/square/new.html I am not getting a 404 error.
Where something.html is present in the account correctly.
Directory new is present in my document root.
Square is not present in my account.
By default, if part of the url points to a file, the rest of the url is treated as so-called "path info". In php you should be able to get this path info by checking $_SERVER['PATH_INFO']. If you don't want Apache to work like this, turn path info off in your main config file (httpd.conf) or in .htaccess in your root directory with the following directive.
AcceptPathInfo Off
For more information, please check the documentation for AcceptPathInfo.
I have a website thats live and another (for amends/approval) that is in a subdirectory called 'approval'. The idea being that once its approved I replace the live site. Is there a way to restrict access to this directory unless you have a direct link - maybe through .htaccess? Any other suggestions regarding protocol for this scenario? Thanks!
I've tried something with .htacces.
You can make a 403 error page. You can't go to a directory unless you have a link.
Make a .htacces file with the following code:
## Error Page
ErrorDocument 403 /403.html
Options -Indexes
the ## means that the line is hidden, for text
ErrorDocument 403 gives the place of the 403 error file. You can also type this: /errors/403.html
Options -Indexes blocks the directory's
I hope that it works for you
I am trying to Custom Error Pages using .htaccess. in this folder:/home/tamp/public_html/sandbox/test, I put .htaccess file, and inside i put this line:
ErrorDocument 404 /home/tamp/public_html/sandbox/test/error.html,
and then in frontend, I did a test, I open mysite/sandbox/test/te.php(te.php does not exist), but it still shows the default error page: The requested URL /test/tes.php was not found on this server. My error.html did not show up.
So what may go wrong here?
with ErrorDocument you can't use full file-system path:
URLs can begin with a slash (/) for local web-paths (relative to the
DocumentRoot), or be a full URL which the client can resolve.
so assuming that your website root folder is sandbox:
ErrorDocument 404 /test/error.html