Forum Moderators: phranque

Message Too Old, No Replies

Error 403 on index page without extension

         

SimiDesign

3:27 pm on Jul 12, 2015 (gmt 0)

10+ Year Member



My index page www.example.com/ shows error 403 on webmaster tools. I notice that when i typed www.example.com on my facebook page and it showed the 403 error. Index page www.example.com/index.html works fine. Also my sitemap shows error on webmaster tools. It works on google though.

Pleaaase can anyone tell me how to fix it?


Thank you

[edited by: bill at 12:50 am (utc) on Jul 13, 2015]
[edit reason] Use example.com [/edit]

not2easy

5:00 pm on Jul 12, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Your "index.html" page should be 301 redirected with a rewrite rule to show at www.example.com/ so if you can access www.example.com/index.html this has not been done yet. You can find examples in the Library of the Apache Forum here: [webmasterworld.com...] - Oh, and welcome to the forums!

BTW - a 403 error means that access is forbidden so you might want to review your .htaccess file overall and see that it is properly doing what you want it to do.

lucy24

5:54 pm on Jul 12, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Now, wait a minute. "index.html" is the default name of an index page-- at least in Apache-- and as such should be automatically served up unless you've got an explicit rule saying otherwise. In fact, it would almost have to be at least two different rules in combination.

Is the problem still happening? You are not supposed to name your own domain in posts, and a moderator will come along shortly to change it, but as long as it is visible I had a look and had no trouble.

Psst! You need to make your own custom 404 page. Don't use the host's default; it looks amateurish at best.

SimiDesign

6:02 pm on Jul 12, 2015 (gmt 0)

10+ Year Member



Thank you very much. :)
and thank you for the advice

I have in my .htaccess this code ..

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]

How long does it take for this to work?

[edited by: bill at 12:53 am (utc) on Jul 13, 2015]
[edit reason] Use example.com [/edit]

SimiDesign

7:06 pm on Jul 12, 2015 (gmt 0)

10+ Year Member



Thank you ... I did not know I can make my own 404 page. I will do that.
I redirected all of my old website pages, which shows 404 error but it does not work. I am not sure what I am doing wrong. The code for redirect i:
RewriteEngine On
Redirect 301 /sk/p.magazineillustration.html http://www.example/portfolio.html
I am not sure if it is correct. :((

Aaah ... i didn't know i can't use my website name. The problem is still happening. All seems to be fine. Only when i share a link of my website without extension on facebook it shows error. I guess i will have to ignore it.

Thank you very much for your time. :)

[edited by: bill at 12:52 am (utc) on Jul 13, 2015]
[edit reason] Use example.com [/edit]

lucy24

7:31 pm on Jul 12, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Uh... what do you mean by "without extension"? Normally that would imply "example.com/index" but that can't possibly be what you mean. It's possible that facebook archives some information so it doesn't know that things are now working properly and there are no 403s.

RewriteEngine On
Redirect 301 ...
These two lines have nothing to do with each other. RewriteEngine On is a directive to switch on mod_rewrite. Redirect by that name is a mod_alias directive. You should never, ever use both. (That is: redirect with both. mod_alias has other uses too, but those are mainly in the config file.) So convert all your mod_alias redirects to use mod_rewrite.

Your two quoted rules are in the wrong order.

The "index.html" redirect should be the second-to-last redirect. The domain-name canonicalization redirect (the one using HTTP_HOST) is then the very last redirect. All other RewriteRules-- including anything that currently uses mod_alias-- come before them.

Edit: For the index.html redirect I recommend using the [NS] flag in addition to the two you already have. They can go in any order [R=301,NS,L]. This prevents the server from having to stop and evaluate conditions when it receives an internal request for the index page. (I don't know if it applies on all Apache versions, but it is definitely valid for 2.2, which is what you've got.)

SimiDesign

6:34 am on Jul 15, 2015 (gmt 0)

10+ Year Member



Hi Lucy 24, Thank you for your replies. I really do have a problem with the .htaccess codes. I dont know if the codes are correct. I found so much written about it on internet, but many times the codes are so different and I am lost. Could you please PLEAAAAASE tell me if this is correct.

DirectoryIndex index.php3 index.php pictures.pl index.html default

THIS SHOULD BE FOR REMOVING / INDEX.HTML

RewriteEngine On
RewriteRule ^index\.html$ / [R=301,NS,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,NS,L]

OR THIS ONE?

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,NS,L]

RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


THIS SHOUL BE THE REDIRECT 404 errors TO NEW PAGE. IS THIS CORRECT.

RewriteEngine on
rewritecond %{http_host} ^http://www.example.com/html/p.intuitionbymyside.html[nc]
rewriterule ^(.*)$ http://www.example.com/portfolio.html/$1 [r=301,nc]

OR WITH THIS

Redirect 301 /hmtl/p.magazine.html http://www.example.com/porfolio.html

Thank you so much for your help.

[edited by: bill at 8:55 am (utc) on Jul 15, 2015]
[edit reason] Use example.com [/edit]

lucy24

7:10 pm on Jul 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



DirectoryIndex index.php3 index.php pictures.pl index.html default

List only the filenames you actually use. The Apache default is index.html; if you are on shared hosting it is a safe bet that they also list index.php and index.htm. But if you normally use some extension other than .html then by all means list them in order of likeliness. On most sites, all directory-index files have the same name, so just name that one. "index.html" and "default" would seem to be redundant. (Is the keyword "default" even valid in 2.2? I don't see it.)

You only need to say "RewriteEngine On" once. The line "RewriteBase" isn't really needed, because all your targets will begin in either / (your root) or full protocol-plus domain, depending.

THIS SHOUL BE THE REDIRECT 404 errors TO NEW PAGE. IS THIS CORRECT.

Nooooo. Do not redirect 404s to anything. Name an ErrorDocument and let the server take it from there:
ErrorDocument 404 /missing.html
ErrorDocument 404 /boilerplate/my404.html
et cetera. Your choice; this can be changed at any time.

Redirect 301

Get rid of any redirects using this syntax. That is: don't delete them. Convert them to mod_rewrite syntax and make sure they are located before the generic redirects.

The second-to-the-last external redirect is for index. Two possibilities:
RewriteRule ^(([^/]+/)*)index\.html http://www.example.com/$1 [R=301,L,NS]
OR
RewriteCond %{THE_REQUEST} ^[A-Z]+ /(([^/]+/)*)index\.html
RewriteRule index\.html http://www.example.com/%1 [R=301,L,NS]
There are some other variations. Notably: if your URL paths never, ever include . periods, then you can express the ([^/]+/)* part as [^.]+ instead. There are some other variations, having more to do with coding style than anything else.

The last external redirect is your domain-name cannonicalization. It is best expressed as a negative:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Now, wait. This is the first I've heard of extensionless URLs. You should bend over backward to avoid -d and -f tests, because they're a lot of extra work for the server. If you really do have a mix of extensionless and html URLs, which is what this rule is for, we can hammer out the optimal form of the rule.

SimiDesign

6:11 am on Jul 16, 2015 (gmt 0)

10+ Year Member



Thank you very much for your time and your help Lucy24.
I am appreciating it very much. :)

lucy24

7:54 am on Jul 16, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I wrote:
RewriteCond %{THE_REQUEST} ^[A-Z]+ /etcetera
### I make this ### same mistake every time. If you're using this version, it has to be
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /
with escaped \ space. Otherwise it's a 500-class error.

SimiDesign

5:35 am on Jul 17, 2015 (gmt 0)

10+ Year Member



Thank you :)
It seems like all is fine now. All I have to do is to deal with the old pages 404 from my previous website. So I will do what you suggested for me.
ErrorDocument 404 /missing.html
ErrorDocument 404 /boilerplate/my404.html

the "missing.html" i should replace this by my old page html?
What does boilerplate mean?

lucy24

5:52 am on Jul 17, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



On my own site, I've got a directory called /boilerplate/ for, well, boilerplate. Error documents and contact form and so on. Your own ErrorDocument directives should use the actual, physical path to your documents, beginning in / for root.

SimiDesign

6:00 am on Jul 17, 2015 (gmt 0)

10+ Year Member



Ah ok ... thank you so much Lucy24
I will do that.

lucy24

6:17 pm on Jul 17, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the "missing.html" i should replace this by my old page html?

Oops, missed this. /missing.html is here the name of your 404 document.

As long as you're in there, I suggest adding another line to say
ErrorDocument 410 /missing.html
again replacing "missing.html" with the actual path-and-name of your 404 document. Yes, it can be the same physical page. You probably don't have any 410s right now, but this way you don't have to worry about it. The Apache default 410 message is even scarier and less user-friendly than the default 404 message.

And then, of course, you'll want a custom 403 page-- harking back to the original question, which I guess has been answered by now.

SimiDesign

6:03 pm on Jul 18, 2015 (gmt 0)

10+ Year Member



Thank you many many many times for your time Lucy.
I am going to learn now how to make 404 and 403 custom pages. :D