I want to redirect some page on 404 page. How may I achieve it using htaccess file.
http://wowriters.com/author/admin/feed/
http://wowriters.com/reflective-portfolio/essay-writing-service
http://wowriters.com/reflective-portfolio/dissertation-service
http://wowriters.com/samples/essay-writing-service
http://wowriters.com/samples/uae
http://wowriters.com/worlds-biggest-beverages/coursework-help-service
http://wowriters.com/worlds-biggest-beverages/buy-essays
Above links should be gone on 404 page.
Kindly help me.
Thanks in advance.
You can use this rule as your topmost rule:
RewriteEngine On
RewriteCond %{REQUEST_URI} /author/admin/feed/ [NC,OR]
RewriteCond %{REQUEST_URI} /reflective-portfolio/(essay-writing|dissertation)-service [NC,OR]
RewriteCond %{REQUEST_URI} /samples/(uae|essay-writing-service) [NC,OR]
RewriteCond %{REQUEST_URI} worlds-biggest-beverages/(buy-essays|coursework-help-service) [NC]
RewriteRule ^ - [L,R=404]
ErrorDocument 404 http://wowriters.com/author/admin/feed/
ErrorDocument 404 http://wowriters.com/reflective-portfolio/essay-writing-service
ErrorDocument 404 http://wowriters.com/reflective-portfolio/dissertation-service
ErrorDocument 404 http://wowriters.com/samples/essay-writing-service
ErrorDocument 404 http://wowriters.com/samples/uae
ErrorDocument 404 http://wowriters.com/worlds-biggest-beverages/coursework-help-service
ErrorDocument 404 http://wowriters.com/worlds-biggest-beverages/buy-essays
All the page not found pages will display the links.
Related
I have htaccess file below
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Redirect /index.html /login.html
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
Options -Indexes
Redirect /index.html /login.html
When user enters index page it should redirect to login.html page.
But it doesn't work.
Redirect /index.html /login.html
im requesting /index
If you are requesting /index then I'm not sure why you are checking for /index.html in your rule. However, you should be using mod_rewrite to construct this redirect since you are already using mod_rewrite for your internal rewrites.
So, have it like this instead:
Options -Indexes
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
RewriteEngine On
RewriteBase /
# Redirect "/index" to "/login"
RewriteRule ^index$ /login [R=302,L]
# Append ".html" if target file exists
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule (.*) $1.html [L]
I've also "fixed" your .html rewrite since this could result in a 500 error for certain requests and there's no need to check that the request does not map to a directory before checking that the request does map to a file.
See the following question on ServerFault that expands on this potential issue regarding .html removal. https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error
I have removed this post from our database entirely but the below link is still showing blank template instead of 404 not found error,
http://www.myconsumercourt.com/complaints/online-shopping/men-clothing/complaint-against-livastar-backlift-technologies-pvt-ltd-1421.html
here is my .htaccess code
RewriteEngine on
ErrorDocument 404 /404.php
RewriteRule ^(.*)/$ /$1 [R,L]
RewriteRule ^complaints/(.*)/(.*)/(.*)-(.*).html$ post-info.php?ticket-number=$4 [L]
RewriteRule ^complaints/(.*)/(.*)$ query-listing.php?sub-category=$2 [L]
RewriteRule ^complaints/(.*)$ subject-list.php?category=$1 [L]
Please help me to redirect my broken page to 404.php page.
Thank you so much.
Kind Regards,
This is because your first RewriteRule is rewriting this url to an existent file.
put the following rule bellow "RewriteEngine on" line to redirect the url to 404.
RewriteCond %{THE_REQUEST} /complaints/online-shopping/men-clothing/complaint-against-livastar-backlift-technologies-pvt-ltd-1421\.html [NC]
RewriteRule ^ - [L,R=404]
my .htaccess file:
RewriteEngine On
# If the request sent by the browser includes login1.php...
RewriteCond %{THE_REQUEST} login1\.php
RewriteRule ^ - [F]
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^ - [F]
ErrorDocument 403 /404.php
ErrorDocument 404 /404.php
# Then you just need a generic rule to rewrite /mysite into login1.php
RewriteRule ^mysite$ login1.php [L]
RewriteRule ^$ index.php [L]
When I try to access the page: http://example.com/login1.php I get an error:
Forbidden
You don't have permission to access /login1.php on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
but I want to display message on page 404.php
Your rules are looping because once you issue forbidden once for /login1.php it keeps on throwing 403 since %{THE_REQUEST} doesn't change.
Have your rules like this to fix it:
RewriteRule ^404\.php$ - [L,NC]
# If the request sent by the browser includes login1.php...
RewriteCond %{THE_REQUEST} (index|login1)\.php
RewriteRule ^ - [F]
ErrorDocument 403 /404.php
ErrorDocument 404 /404.php
# Then you just need a generic rule to rewrite /mysite into login1.php
RewriteRule ^mysite$ login1.php [L]
RewriteRule ^$ index.php [L]
So I know this may seem a little strange but I for sake of consistency, I would like all my urls to appear in this form:
http://example.com/page/
So far I have gotten the regular pages working but I cannot seem to get the error pages working properly.
If the user visits a page or directory that does not exist, I would like the browser to hard redirect to:
http://example.com/404/
This directory, however, will not actually exist. The real location of the error page will be under
/pages/errors/404.php
Also, although I do not need an exact answer for all the various errors (400, 401, 403, 404, 500), I will be applying whatever method is given to redirect all of these to their "proper" URL's
eg.
http://example.com/400/
http://example.com/500/
etc.
Any ideas?
Try this in your .htaccess:
.htaccess
ErrorDocument 404 http://example.com/404/
ErrorDocument 500 http://example.com/500/
# or map them to one error document:
# ErrorDocument 404 /pages/errors/error_redirect.php
# ErrorDocument 500 /pages/errors/error_redirect.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /pages/errors/404.php [L]
RewriteCond %{REQUEST_URI} ^/500/$
RewriteRule ^(.*)$ /pages/errors/500.php [L]
# or map them to one error document:
#RewriteCond %{REQUEST_URI} ^/404/$ [OR]
#RewriteCond %{REQUEST_URI} ^/500/$
#RewriteRule ^(.*)$ /pages/errors/error_redirect.php [L]
The ErrorDocument redirects all 404s to a specific URL, all 500s to another url (replace with your domain).
The Rewrite rules map that URL to your actual 404.php script. The RewriteCond regular expressions can be made more generic if you want, but I think you have to explicitly define all ErrorDocument codes you want to override.
Local Redirect:
Change .htaccess ErrorDocument to a file that exists (must exist, or you'll get an error):
ErrorDocument 404 /pages/errors/404_redirect.php
404_redirect.php
<?php
header('Location: /404/');
exit;
?>
Redirect based on error number
Looks like you'll need to specify an ErrorDocument line in .htaccess for every error you want to redirect (see: Apache ErrorDocument and Apache Custom Error). The .htaccess example above has multiple examples in it. You can use the following as the generic redirect script to replace 404_redirect.php above.
error_redirect.php
<?php
$error_url = $_SERVER["REDIRECT_STATUS"] . '/';
$error_path = $error_url . '.php';
if ( ! file_exists($error_path)) {
// this is the default error if a specific error page is not found
$error_url = '404/';
}
header('Location: ' . $error_url);
exit;
?>
Put this code in your .htaccess file
RewriteEngine On
ErrorDocument 404 /404.php
where 404.php is the file name and placed at root. You can put full path over here.
Try adding this rule to the top of your htaccess:
RewriteEngine On
RewriteRule ^404/?$ /pages/errors/404.php [L]
Then under that (or any other rules that you have):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ http://domain.com/404/ [L,R]
In your .htaccess file , if you are using apache you can try with
Rule for Error Page - 404
ErrorDocument 404 http://www.domain.com/notFound.html
I recently changed the filename of some of my pages. For example
work1.html to acn-website.html
work2.html to inkdrawn-website.html
etc.
I currently have the following in my htaccess file;
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^fullfatdesigns\.co.uk$
RewriteRule (.*) http://www.fullfatdesigns.co.uk/$1 [R=301,L]
ErrorDocument 404 /error/404.php
ErrorDocument 403 /error/403.php
How do I go about inserting multiple 301 re-directs into my existing file?
Thank you
Wayne
You could add
RewriteRule oldPage\.html http://www.fullfatdesigns.co.uk/newPage.html [R=301,L]
after RewriteEngine on for every redirect.