Forum Moderators: phranque

Message Too Old, No Replies

Forbidden Error in mod rewrite

Forbidden error in mod rewrite

         

fahad direct

1:40 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



Hi,
I am bit confused why i am getting forbidden error in some of the places where as it works fine in the rest of the cases as error message is:

You don't have permission to access
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

My URL is:

http://electronics.example.com/11101-PG1-0-VTelevision_Screen_Size--30.1%20%20-%2035%20,Television_Screen_Size--35.1%20%20-%2040%20,Television_Screen_Size--40.1%20%20-%2045%20,Television_Manufacturer--Hitachi,Flat_Panel_TV_Type--LCD%20Television,High_Def_Television--HD-Ready,Built_In_Digital_Tuner_Freeview--Yes,/P-S/Flat-Panel-LCD-TV

and code in my .htaccess file is:

RewriteRule ^(.+)1(.+)0(.+)-PG(.*)-(.*)-V(.*)/P(.*)-S(.*)/(.*)$ /products/index.php?cid=$1&subcat1=$2&subcat2=$3&subcat3=$4&subcat4=$5&varr=$6&page=$7&srch=$8&type=$9 [L]

Is there any server configuration i need to do?

[edited by: jdMorgan at 2:45 am (utc) on Apr 28, 2010]
[edit reason] Example.com [/edit]

g1smd

5:02 pm on Apr 26, 2010 (gmt 0)

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



Those multiple (.*) patterns should in reality be stopping your server dead for every URL request made of it.

It is likely that each request will need tens of thousands of "back off and retry" attempts in order to find a match.

example.example.com/11101-PG1-0-VTelevision_Screen_Size--30.1%20%20-%2035%20,Television_Scr
een_Size--35.1%20%20-%2040%20,Television_Screen_Size--40.1%20%20-%2045%20,Television_Manuf
acturer--Hitachi,Flat_Panel_TV_Type--LCD%20Television,High_Definition_Television--HD-Rea
dy,Built_In_Digital_Tuner_Freeview--Yes,/P-S/Flat-Panel-LCD-TV


Additionally, the spaces in the URL (converted to %20 each time) are a complete nightmare, and you have way too many words in the URL. This is pure keyword spam and no benefit to either users or searchengines.

Rather than "fixing" this code, I would advise a complete rethink as to the valid URL formats your site will use.

fahad direct

12:45 pm on Apr 27, 2010 (gmt 0)

10+ Year Member



There is a form on website, when someone checks the mulitple checkboxe items for search then it combines keywords against those selected items to make a url with GET method of Form and i have no other method to reduce the url size though on your recommendations i have changed my mod rewrite pattern something like this now:

^([0-9]+)1([0-9]+)0([0-9]+)-PG([0-9]*)-([0-9]*)-V(.*)/P([0-9]*)-S(.*)/(.*)$

as i believe it will reduce the server load now but still i am getting the same error even after removing the spaces as i have checked the either way so will be more appreciated if you can help me to make this url workable.

jdMorgan

2:57 am on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Much better, but I'd suggest that you use negative-match subpatterns to replace all but the last ".*" if possible:

^([0-9]+)1([0-9]+)0([0-9]+)-PG([0-9]*)-([0-9]*)-V([^/]*)/P([0-9]*)-S([^/]*)/(.*)$

I also agree that it would be beneficial to get rid of the %20-encoded spaces in your URLs.

Back to the main problem...

You don't have permission to access

Is that all there is in that message? -- No URL-path information is provided?

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

This indicates several possible problems. A custom 403 errordocument has been declared, but access to that custom error document is being denied -- possibly based on the same reason that the original request was denied. I don't see any access-control code in what you posted above, so I can't comment further.

You say some requests "work" and some don't. What is the difference between a URL that works and one that does not?

What do you see in the server error log when you get one of these errors?

I've posted several questions here, and I don't see much chance of progress until they're thoroughly answered.

Jim

fahad direct

11:23 am on Apr 28, 2010 (gmt 0)

10+ Year Member



Hi Jim, thanks for your help.

Here are my replies please:

It works for:
1) The full error message coming as:

Forbidden
You don't have permission to access /11101-PG1-0-VTelevision_Screen_Size--40.1 - 45 ,Television_Manufacturer--Apple__Daewoo__Hitachi__Beko,Flat_Panel_TV_Type--LCD Television__Plasma Television__OLED Television__LCD Television Combi,High_Definition_Television--HD-Ready__Not HD-Ready,Built_In_Digital_Tuner_Freeview--Yes/P-S/Flat-Panel-LCD-TV on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.


2)It is working for:

mydomain.com/11101-PG1-0-VTelevision_Screen_Size--40.1%20%20-%2045%20,Television_Manufacturer--Apple__Daewoo__Hitachi__Beko,Flat_Panel_TV_Type--LCD%20Television__Plasma%20Television__OLED%20Television__LCD%20Television%20Combi,High_Definition_Television--HD-Ready__Not%20HD-Ready/P-S/Flat-Panel-LCD-TV

but not for:

mydomain.com/11101-PG1-0-VTelevision_Screen_Size--40.1%20%20-%2045%20,Television_Manufacturer--Apple__Daewoo__Hitachi__Beko,Flat_Panel_TV_Type--LCD%20Television__Plasma%20Television__OLED%20Television__LCD%20Television%20Combi,High_Definition_Television--HD-Ready__Not%20HD-Ready,Built_In_Digital_Tuner_Freeview--Yes
/P-S/Flat-Panel-LCD-TV

where as only this is additional coming in the end:
,Built_In_Digital_Tuner_Freeview--Yes

3) in error log getting message as:

File does not exist: homepath/electronics/404.shtml, referer: mydomain.com/11101-PG1-0-V/P-S/Flat-Panel-LCD-TV

Looking forward to hear.

fahad direct

12:09 pm on Apr 28, 2010 (gmt 0)

10+ Year Member



I am just thinking does it why because of so long url and server is considering it as a subfolder like:

11101-PG1-0-VTelevision_Screen_Size--40.1%20%20-%2045%20,Television_Manufacturer--Apple__Daewoo__Hitachi__Beko,Flat_Panel_TV_Type--LCD%20Television__Plasma%20Television__OLED%20Television__LCD%20Television%20Combi,High_Definition_Television--HD-Ready__Not%20HD-Ready,Built_In_Digital_Tuner_Freeview--Yes

which is too big and in unix we can't have it?

jdMorgan

4:04 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well the first thing to do is to define (create) the custom 404 page that you have declared using either ErrorDocument directives in .htaccess or in your "control panel" (and the custom 403 page too, if also declared.)

Either that, or remove the ErrorDocument directives or reset the "control panel" settings so that /homepath/electronics/404.shtml is not declared as a custom 404 error page. (Note that this may be a simple error; If /404.shtml *does* exist, then the problem may be that you've declared the URL-paths to errordocuments *without* a leading slash...

You need to get your error-handling fixed in order to get good test results. Then you can proceed to figure out why the "bad" URLs do not match your rule(s) and are therefore getting a 404-Not Found, or a 403-Forbidden response.

Jim

fahad direct

1:27 am on Apr 30, 2010 (gmt 0)

10+ Year Member



Hi Jim,
Thank you very much it really resolved.