Results 1 to 13 of 13
-
04-23-2012, 07:48 PM #1Junior Guru Wannabe
- Join Date
- Mar 2009
- Posts
- 52
How to generate error 404 with .htaccess
hello
I need to generate a error 404 for all url of my website who contain a specific attribute inside.
In fact I have many url who contain the attribute ?fontstyle=f-larger AND ?fontstyle=f-smaller and I would like find a solution for let me generate 404 error when trying to access to this kind of url.
If is not possible maybe I can redirect to a fake/inexistent url like www.site.com/fake.html who will result in a error 404...but I did not see how to do using .htaccess...
any clue please ??
thank
-
04-23-2012, 09:38 PM #2Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
Something like this should give you a start:
Code:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} fontstyle=f-larger RewriteCond %{QUERY_STRING} fontstyle=f-smaller RewriteRule .* - [G,L] </IfModule>
If you do that though, watch out for any other rewrite rules that may catch the missing file request and redirect / rewrite it again (eg. the standard rules on most CMSs for SEO-friendly links that send everything to index.php).Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
04-24-2012, 03:35 AM #3Junior Guru Wannabe
- Join Date
- Mar 2009
- Posts
- 52
many thank for your reply...
Yes typically I use Joomla with SEF enabled that mean I have my .htaccess enabled with some standard mandatory rules active inside (related like you say for SEO-friendly links) and with also many more custom security rules.
I tried your suggested rule but this seem to not work..
Is because your rules must be place in a specific position or because possible conflict with others rules ?
-
04-24-2012, 12:27 PM #4WHT Addict
- Join Date
- Sep 2011
- Posts
- 128
ErrorDocument 404 /notfound.html
P.S: IE will redirect your error page to Bing if your custom error page is smaller than 512 byte.- I am a PHP developer. I'm not a webhosting owner, I have never run a webhosting business before.
- English is not my primary language.
-
04-24-2012, 12:44 PM #5Junior Guru Wannabe
- Join Date
- Mar 2009
- Posts
- 52
-
04-24-2012, 01:59 PM #6WHT Addict
- Join Date
- Sep 2011
- Posts
- 128
You ought to add those codes into the your .htaccess file.
Hope this helps- I am a PHP developer. I'm not a webhosting owner, I have never run a webhosting business before.
- English is not my primary language.
-
04-25-2012, 06:06 AM #7Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
ErrorDocument 404 will not do what you want - it just controls the page shown after you get a 404 error, it won't generate one.
Most of the standard rewrite rules include [QSA] (query-string append) so your condition ("?fontstyle=f-larger AND ?fontstyle=f-smaller") should persist even after any earlier rewrite, but it's probably worth trying this at the beginning of the top-level .htaccess so it gets processed first. If it still doesn't work, what exactly is the url you're trying to match? (Blank out the domain name if you like). If the url is malformed then perhaps the QUERY_STRING variable as seen by Apache won't include both those parameters.Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
04-25-2012, 07:19 AM #8Junior Guru Wannabe
- Join Date
- Mar 2009
- Posts
- 52
Yes I thought this suggestion wont make any effect...
I tried to put your rule on the first position but this change nothing...
My url look like this:
http://www.site.com/de/category/fiel...ge:2/limit:10/
Sometime the attribute "fontstyle-f-larger" or "fontstyle-f-smaller" is placed in middle, start or end url...depend.
Before I had the attribute "?fontstyle-f-smaller" always at the end of url but now it seem the fact to have make some task inside Google Webmaster Tools help to remove those url from Google index...but I'm unsure if this is the real reason.
any clue ?
many thank for your support
cheers
-
04-25-2012, 08:25 AM #9New Menber
- Join Date
- Apr 2012
- Posts
- 3
By creating 404 error for all URLs, will not be bad from web promotion point of view.
-
04-25-2012, 10:43 AM #10Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
Code:http://www.site.com/de/category/fieldname1/fieldname2/menu/fontstyle-f-larger/page-2/limit-5/page:2/limit:10/
Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
04-26-2012, 03:45 PM #11Junior Guru Wannabe
- Join Date
- Mar 2009
- Posts
- 52
Sorry I was maybe not clear... My english is poor and sometime I'm not able to well explain everything.
In fact I would like generate this 404 error only when the following exact attribute is present in the rewritted url:
fontstyle=f-larger
OR
fontstyle=f-smaller
No matter if the attribute is rewritted by the sef engine or if other character are present before or after the attribute (like a backslash or other).
Now I don't know if this is possible to do..
thank
-
04-26-2012, 08:46 PM #12Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
Yes, it's possible. You could use the REQUEST_URI server variable instead of QUERY_STRING and the [OR] flag to redirect on either condition. But again, the details matter. Is it "fontstyle=f-larger" or "fontstyle-f-larger" as shown in your example url? Assuming the latter, this should do it:
Code:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} fontstyle-f-larger [OR] RewriteCond %{REQUEST_URI} fontstyle-f-smaller RewriteRule .* - [G,L] </IfModule>
Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
04-28-2012, 01:38 PM #13Junior Guru Wannabe
- Join Date
- Mar 2009
- Posts
- 52
excellent your code now work and if I try to access to an url who contain the attribute I get this message:
*******************
Gone
The requested resource
is no longer available on this server and there is no forwarding address. Please remove all references to this resource.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
******************
But now I get also a error 403 and I don't know if this is a good thing.
In fact like you have probably understand, I try to remove all url of my site who contain the attribute fontstyle=f-larger OR fontstyle=f-smaller because those url was a case of duplicate content and Google don't like this.
MY Joomla template had 2 button who allow to increase or decrease the font size in all page of my site and give this choice to visitors. That mean my site is more less indexed 3 time by google:
1) With normal font size
2) With big font size
3) With small font size
After discovering this problem I removed those "font size button" from my template, but is now too late because all my pages are present in google index.
For informations here a list of common error about HTTP status codes with some google comment:
http://support.google.com/webmasters...n&answer=40132
If you read about error 410, google suggest to use also an error 301 an redirect to another page but in my case this is not possible because I don't have any page to redirect and my goal was to get an error 404.
Ideally a true error 404 would be better for allow google understand this url is really no more available and need to be removed from his index. Now I'm not sure if google will consider an error 410 or error 403 like an error 404.
Maybe it would be better to use a error 301 instead to error 410 and redirect to a fake inexistent page who will produce a true error 404 ???
have you any advices about this ??
thank again
cheers
Similar Threads
-
.htaccess, indices, & 404 error
By expatCanuck in forum Hosting Security and TechnologyReplies: 4Last Post: 06-07-2009, 04:44 PM -
.htaccess Custom 404 Error Page returning 200 code
By Lanny in forum Hosting Security and TechnologyReplies: 10Last Post: 08-09-2007, 07:42 PM -
using htaccess for 404 error trapping
By sametch in forum Dedicated ServerReplies: 10Last Post: 01-24-2003, 03:01 AM -
.htaccess 404 error message
By Ellmb in forum Hosting Security and TechnologyReplies: 3Last Post: 03-05-2001, 01:17 PM -
.htaccess and 404 error page
By astralexis in forum Hosting Security and TechnologyReplies: 2Last Post: 12-28-2000, 03:56 AM