Error 403 Redirect .htaccess
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 Learn more about hiring developers or posting ads with us Stack 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 each other. Join them; it only takes a minute: Sign up SImple way to redirect 403 and 404 errors to the main page htaccess up vote 0 down vote favorite As the title says is there any easy way to redirect every forbidden error and page not found to my main page index.php? Here is my htaccess don't think it will be of any use but here it is: ErrorDocument 404 /leaguenotes/administration/cms/new_patch ErrorDocument 403 /leaguenotes/administration/cms/new_patch Options ALL -Indexes RewriteEngine On RewriteRule ^([0-9/.]+)$ index.php?Patch_No=$1 [NC,L] RewriteRule ^([0-9/.]+)&([0-9a-zA-Z_-]+)$ index.php?Patch_No=$1&tab=$2 [NC,L] RewriteRule ^patches php/patches.php [NC,L] RewriteRule ^([0-9a-zA-Z_-]+)$ index.php?Champion=$1 [NC,L] .htaccess share|improve this question edited Jun 22 '15 at 15:45 asked Jun 22 '15 at 15:29 Higeath 548 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote You can add these 2 lines on top of your .htaccess: ErrorDocument 404 / ErrorDocument 403 / This will redirect every 403 and 404 errors to your home page. share|improve this answer answered Jun 22 '15 at 15:31 anubhava 382k32159231 Could I redirect it to certain index? e.g. localhost/leaguenotes/administration/cms/new_patch I would like redirect this to localhost/leaguenotes which is the homepage –Higeath Jun 22 '15 at 15:33 Yes sure you can use any URL in the target. So ErrorDocument 404 /leaguenotes/administration/cms/new_patch will also work –anubhava Jun 22 '15 at 15:35 that's what ive tried ErrorDocument 404 /leaguenotes/administration/cms/new_patch ErrorDocument 403 /leaguenotes/administration/cms/new_patch and i got: Additionally, a 301 Moved Permanently error was encountered while trying to use an ErrorDocument to handle the request. I want to redirect every error from every possible subpage to mai
custom error pages using .htaccess rule Sometimes while browsing sites on the web, you must have noticed that some links show errors like: - You don’t have permission to access the page. - The requested URL /test.php is not found on this server. Here is an example: http://phpnuke.org/test.php Here it shows your server info and port. This is a server generated message. For each type of error, the server shows a static HTML page. However, to make your site more http://stackoverflow.com/questions/30983968/simple-way-to-redirect-403-and-404-errors-to-the-main-page-htaccess attractive you can create you own customized page and show it in your web application instead of showing the system generated message. Also you can redirect the user to the index page. This can be handled by using .htaccess file. Steps: Create your own customized error pages for 404 or 403 or any other error type. You can create it with http://burnignorance.com/web-development-tips/redirect-403-404-error-pages-to-the-custom-error-pages-using-htaccess-rule/ your own logo and content. Create the .htaccess file in the root virtual directory and write the following code in the .htaccess file. ErrorDocument 404 404.html ErrorDocument 403 403.html
If you want to show your index page, if any of the 404 or 403 error occurs. Then write the following line in your htaccess file. ErrorDocument 404 index.html ErrorDocument 403 index.html Here are some websites, those uses their own customized error page. http://us.php.net/manual/en/test http://php.resourceindex.com/test Examples of server error code: 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found Reference for server error code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html Supriti Panda, Sr Developer, Mindfire Solutions. Related Tags: .htaccess, Redirection, Server Error, web development Author : Supriti Panda Leave a Reply Click here to cancel reply. Name (required) Mail (will not be published) (required) Website Enter Captcha Code * × seven = 63 Burn Ignorance is a knowledge initiative by Mindfire Solutions Subscribe With Us Subscribe Subscribe to our mailing list to get the updates to your email inbox... Burn Ignorance is a knowledge initiative by Mindfire Solutions © Copyright Burn Ignorance 2007-2016.the 'Enhancing a Simple PHP Application' course and have encountered an issue when using the [R] flag to redirect https://teamtreehouse.com/community/error-403-php-htaccess-redirect-rules pages. My .htaccess code is below: RewriteEngine On RewriteRule ^shirts/$ shirts/shirts.php RewriteRule ^shirts/([0-9]+)/$ shirts/shirt.php?id=$1 RewriteRule ^receipt.php$ receipt/ [R=301] RewriteRule ^contact.php$ contact/ [R=301] RewriteRule ^shirts.php$ shirts/ [R=301] The http://webmasters.stackexchange.com/questions/77168/how-can-i-use-htaccess-to-respond-with-403-forbidden-status-for-urls-that-conta first 2 rules work fine and the other rules work when I remove the [R] flag. When the redirect flag is included I get the error: Access error 403 forbidden! You don't have permission to access the requested directory. There is either no index document or the directory is read-protected. If you think this is a server error, please contact the webmaster. Error 403 I am using XAMPP and my browser is Chrome. Any help would be great :) Ben Rubin Pro Student error 403 redirect 14,656 Points Ben Rubin Ben Rubin Pro Student 14,656 Points 3y ago Try putting a / before the path that you're redirecting to. For example RewriteRule ^receipt.php$ /receipt/ [R=301] 4 Answers Tiffany McAllister 25,789 Points Tiffany McAllister Tiffany McAllister 25,789 Points almost 3 years ago Hi Ben, Thanks for your reply. That will not work because the site is not in the root of the htdocs folder. The site is in it's own subfolder 'shirts4mike' within the htdocs directory. Ben Rubin Pro Student 14,656 Points Ben Rubin Ben Rubin Pro Student 14,656 Points 3y ago How about this. Assuming you want your .htaccess in the root of the htdocs folder and the site itself in the htdocs/shirts4mike folder, try this line in your .htaccess: RewriteRule ^(shirts4mike)/receipt.php$ /$1/receipt/ [R=301] This is working for me. Browser caching seems to sometimes make it look like it's not working when it is working correctly, or vice versa, so try clearing your cache too. Alternatively, i
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 Learn more about hiring developers or posting ads with us Webmasters Questions Tags Users Badges Unanswered Ask Question _ Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How can I use .htaccess to respond with 403 forbidden status for URLs that contain a query string? up vote 2 down vote favorite Some bots have been crawling my site for every link that ends with: ?utm_source=dlvr.it&utm_medium=twitter I haven't checked out its IP. Then other bots (10+) follow the link rules ?utm_source=dlvr.it&utm_medium=twitter and also crawl my site. This results in a huge amount of traffic which then causes my site to shut down. I have added 10+ other bots into my blacklist with an HTTP 403 status code when they access my site. But I think the best way is to find out the first bot which crawled my site for every link that ends with: ?utm_source=dlvr.it&utm_medium=twitter Or, use a an HTTP 403 redirect status code when the URL contains: ?utm_source=dlvr.it&utm_medium=twitter I know of some ways to add .htaccess code that would prevent someone from crawling my xmlrpc.php page, such as: