There is a issue of unstructured link like (https://example.com/digital-marketing.php/ercbierubcrei)
How can I redirect its to main root?
My .htaccess not working, I’m using below code in .htaccess:-
RewriteEngine On
ErrorDocument 404 /example.com
4
Answers
A simple 301 redirect will do the job.
use Complete url of your site. Like this
Please refer to below
.htaccess
examples:Redirect
http://yourdomain/digital-marketing.php/apple
tohttp://yourdomain/
:Redirect
http://yourdomain/digital-marketing.php/orange
tohttp://yourdomain/ref?code=orange
:I assume
/digital-marketing.php
is a file on your filesystem. In which case/ercbierubcrei
is additional pathname information (or path-info). By default, the PHP handler allows path-info, so/digital-marketing.php
is still served but at the different URL (if that’s what you mean by "unstructured link"?).You can simply disable path-info on these URLs by setting the following at the top of your
.htaccess
file:Now, any URL that contains path-info will trigger a 404 instead and your custom 404 error document will be called. (You can still override this behaviour with mod_rewrite if you wish.)
Alternatively, if you wanted to redirect
/digital-marketing.php/ercbierubcrei
to/digital-marketing.php
(is that what you mean by "redirect its to main root"?*1) then you can do something like the following near the top of your.htaccess
file using mod_rewrite:This redirects a URL of the form
/<something>.php/<anything>
to/<something.php
, effectively discarding the path-info portion of the URL.(*1 – If by "main root" you do literally mean the document root of the site then that is not recommended. Google would likely treat this as a soft-404 anyway. A custom 404 with a meaningful message would be preferable.)
This does not look "valid". The 2nd argument to the
ErrorDocument
directive should ideally be a local URL-path to the document that handles the error response.For example: