Default Directory Index - .htaccess

I have a website :
http://www.exclusivetech.net/clients/fashion/
If you look at the url then i have not mention any page/file name to be executed, it will display index.php bydefault.. I want it to show page not found error against this and any sub directory if particular filename is not mentioned in any URL .....

Write this in your .htaccess
ErrorDocument 404 /path/to/yourerrorpage.html

Related

How to make 404 error on homepage?

I have an empty domain, and would like to return a 404 error when people go to the homepage, or any other URL. Currently, when I go to the domain, I'm being displayed the empty directory.
How can I achieve that?
I'm being displayed the empty directory.
I assume you mean you are being shown an (Apache generated) index of that directory (which would appear to be empty). This is a "feature" of Apache. To disable directory indexes then include the following at the top of the .htaccess file in your document root:
Options -Indexes
However, this will result in a 403 Forbidden being served when accessing a directory that does not contain a DirectoryIndex document (because server-generated directory indexes are "forbidden"). To explicitly return a 404 for all requests, include the following below the above in the .htaccess file:
RewriteEngine On
RewriteRule ^ - [R=404]
This uses mod_rewrite to instruct Apache to return a 404 status (default error page) for all requests.
However, this does assume that you have not defined a custom 404 ErrorDocument (otherwise you'll get a 500 error resulting from a rewrite loop).

How can I redirect 301 all error pages to sub folder?

I want to redirect 301 with htaccess file my broken URLs. What do I mean? If visitor come to this link: http://mydomain.com/blablablablablablablabla34234234.php he probably will get an 404 error so I want my "404 page" will be in sub folder. like this:
http://mydomain.com/somenonpage.php to http://mydomain.com/sub/somenonpage.php
http://mydomain.com/blablablablabla to http://mydomain.com/sub/blablablablabla
etc.
If you want to have a custom 404 page you do not do a 301 Redirect, 301 is to redirect an old link to a new URL. Say you had a popular post but decided to change the url for SEO reasons but the old url was heavily backlinked. You would then use a 301 to make sure that those backlinks got associated with your new url.
To make a custom 404 all you need to do is edit your http.conf file and add a path to your custom 404 page. By default I think the file belongs in your root directory named 404.html.
If you need the fileto have a different name or location you can edit the file path at the line beginning line ErrorDocument 404 /404.html.

htaccess - rewriting rules

Google Webmaster tools gives me a hint that I have 2 pages with the exact same content.
For example:
/airports/romania/115.php
/airports/romania/115.phphey1
In the htacces file i have this:
RewriteRule airports/(.*)/([0-9]{1,}).php airports_list.php?airport=$2&country_air=$1
I've checked and double checked and triple checked all my code in airports_list.php and every other file on the server. I can't find "hey1" anywhere.
In order to solve my problem, I think I have to redirect a link like www.mydomain.com/airports/romania/115.phphey1 to a 404 page.
How do I do that ?
The following is also working inside my .htaccess file :
ErrorDocument 404 http://www.mydomain.com/404.php
If you put a dollar sign at the end of the regex, it stops matching and so garbage at the end of '.php' and goes to the 404.
RewriteRule airports/(.*)/([0-9]{1,}).php$ airports_list.php?airport=$2&country_air=$1

Use 404 ErrorDocument that is in a sub directory

I have a htaccess file in a sub folder like so:
/subfolder/.htaccess
In the htaccess file the following code to set a 404 ErrorDocument
ErrorDocument 404 /404.php
The issue is the 404 page in the root directory is loaded rather than the one in the /subfolder/ folder. I can't simply change the htaccess file to use /subfolder/404.php because the system is going to be installed in lots of different places.
Is there a way to reference the files in the directory that the htaccess is in?
I just had the same problem and found you page...If you have domain/folder and want to redirect anything from the folder back to the domain's index, use ErrorDocument 404 /
...I'm not sure if this goes to the root folder or one folder up, but in your case (and mine) they are one in the same.
Hope this helps!

404 custom error template .htaccess

Ok, I have a problem, my .htaccess code is:
RewriteEngine on
ErrorDocument 404 /notfound.html
and I have not found.html near .htaccess.
Why is it not working? I don't believe what I'm seeing. I took the tutorial from here
http://www.htaccessbasics.com/404-custom-error-page/
I just want that every time I access www.site.com/ajfasoijfiajsfijaofij to show what is it in notfound.html.
when using ErrorDocument , the file you're specifying is relative to DOCUMENT ROOT not .htaccess location!
Edit:
assume you have notfound.html and you want to use it for folder dir01, you create an htaccess file inside this folder and add this:
ErrorDocument 404 /dir01/notfound.html
If you want to access your file(notfound.html) in browser it would be http://www.example.com/dir01/notfound.html. that's all I could explain!
You can use in your .htaccess file the following code:
RewriteBase /

Resources