Apache Rewrite 404 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business iis url rewrite 404 error Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation url rewrite 404 error iis7 Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like
Apache Tomcat 404 Error
you, helping each other. Join them; it only takes a minute: Sign up Redirect to Apache built-in 404 page with mod_rewrite? up vote 17 down vote favorite 3 Is there a way to actively serve Apache's default,
Apache 404 Error Page
built-in 404 page for a number of URLs using mod_rewrite? Not a custom error document, but a rule like RewriteCond %{REQUEST_URI} ^/dirname/pagename RewriteRule -- serve 404 page ----- I know how to build a PHP page that sends the 404 header and have mod_rewrite redirect all the URLs there but I would prefer a solution that is based on mod_rewrite only. I just had the idea of redirecting to a non-existent address: RewriteCond %{REQUEST_URI} ^/dirname/pagename apache 404 error on a file that exists RewriteRule .* /sflkadsölfkasdfölkasdflökasdf but that would give the user the message "/sflkadsölfkasdfölkasdflökasdf does not exist" on the error page, which looks a bit unprofessional. apache mod-rewrite share|improve this question edited Nov 16 '15 at 19:55 David Moles 13k1076139 asked Mar 15 '10 at 12:42 Pekka 웃 302k93694911 1 Voter to close: mod_rewrite questions are officially all right on SO. meta.stackexchange.com/questions/39063/… –Pekka 웃 Mar 15 '10 at 12:44 2 +1 nice question! –richsage Mar 15 '10 at 13:05 add a comment| 4 Answers 4 active oldest votes up vote 25 down vote accepted You can use the R flag on the RewriteRule to force a redirect with a given status code: While this is typically used for redirects, any valid status code can be given here. If the status code is outside the redirect range (300-399), then the Substitution string is dropped and rewriting is stopped as if the L flag was used. So this: RewriteRule ^/?page\.html$ - [R=404] would return the default 404 page for /page.html. Since this is a regexp, remember the escaping \. and anchoring $. - is ignored (i.e. "the Substitution string is dropped"), but there still needs to be something there to keep the rule well-formed. share|improve this answer edited Sep 13 '12 at 12:03 tuomassalo 3,32022134 answered Mar 15 '10 at 13:19 mercator 21.2k54961
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta
Apache 404 Error Log
Discuss the workings and policies of this site About Us Learn more apache 404 error but file exists about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack apache 403 error Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping http://stackoverflow.com/questions/2447106/redirect-to-apache-built-in-404-page-with-mod-rewrite each other. Join them; it only takes a minute: Sign up Apache rewrite to 404 except for matched query up vote 1 down vote favorite I'm trying to handle logically simple operation, but apache rewrite does not handle my website's query string requests. I heard it does not do it eventually. Still cannot understand its regex syntax. http://stackoverflow.com/questions/9211360/apache-rewrite-to-404-except-for-matched-query RewriteEngine on RewriteBase / #RewriteCond %{QUERY_STRING} ^\?category=([a-z])$ // WHY DO I NEED THIS? RewriteRule ^!(?category=[a-z]+|?do=[a-z]+)$ [R=404,L,NC] Goal is to send the client to 404 for any query NOT matching /?category=[a-z]+ and /?do=[a-z]+. It would be much better if it's possible to load patterns from the text file. The Apache documentation is poor and Google does not help as well. apache mod-rewrite share|improve this question edited May 31 '15 at 11:08 kwoxer 86711326 asked Feb 9 '12 at 13:04 Alex G 1,42482150 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted Don't include the query string inside RewriteRule. It is matched in RewriteCond. RewriteEngine on RewriteBase / # For js & css # Normally this would be done with: # RewriteCond %{REQUEST_FILENAME} !-f # But since you might have files here you're trying to put a 404 on, # we'll do it differently, matching css & js files RewriteCond %{REQUEST_FILENAME} !^(.*)\.(css|js)$ #Conditions check if either query param is missing (negated with !) RewriteCond %{QUERY_STRING} !category=([a-z]+) Rewrit
generic error responses in the event of 4xx or 5xx HTTP status codes, these responses are rather stark, uninformative, and can be intimidating to site users. You may https://httpd.apache.org/docs/2.4/custom-error.html wish to provide custom error responses which are either friendlier, or in some language other than English, or perhaps which are styled more in line with your site layout. Customized error responses can be defined for any HTTP status code designated as an error condition - that is, any 4xx or 5xx status. Additionally, a set of values are provided, so that the error document can be customized further based on 404 error the values of these variables, using Server Side Includes. Or, you can have error conditions handled by a cgi program, or other dynamic handler (PHP, mod_perl, etc) which makes use of these variables. Configuration Available Variables Customizing Error Responses Multi Language Custom Error Documents See alsoComments Configuration Custom error documents are configured using the ErrorDocument directive, which may be used in global, virtualhost, or directory context. It may be used in apache 404 error .htaccess files if AllowOverride is set to FileInfo. ErrorDocument 500 "Sorry, our script crashed. Oh dear" ErrorDocument 500 /cgi-bin/crash-recover ErrorDocument 500 http://error.example.com/server_error.html ErrorDocument 404 /errors/not_found.html ErrorDocument 401 /subscription/how_to_subscribe.html The syntax of the ErrorDocument directive is: ErrorDocument <3-digit-code>