i have site there both url are working as follow
https://domainname/abc
https://domainname//abc
so i just want to redirect //abc to 404 error page for preventing duplicate content i try following rule but didn't work.
RewriteRule ^//(.*)$ 404
ErrorDocument 404 https://domain_name/404
i also try using RedirectMatch as follow
<IfModule mod_alias.c>
RedirectMatch 404 ^//(.*)$ https://domain_name/$1
</IfModule>
Related
in the .htaccess I have added the following
<IfModule mod_alias.c>
RedirectMatch 302 ^/contact\.html$ /contact-us
www.example.com/contact.html redirects to www.example.com/contact-us.php?q=contact.html
i need to redirect www.example.com/contact.html to www.example.com/contact-us.php?1=contact.html
I want to make a redirection from an old URL https://www.mywebsite.eu/en/form/emsos-2017/ to the homepage https://www.mywebsite.eu/.
I do not have access to the webserver but I know that the language prefix (in this case /en) is managed by the CodeIgniter framework.
mod_alias and mod_rewrite are enabled.
So I already tried that but none worked.
Redirect https://www.mywebsite.eu/en/form/emsos-2017 https://www.mywebsite.eu
RewriteRule ^emsos-2017/ https://www.mywebsite.eu [R=301,L]
RedirectMatch 301 ^/emsos-2017$ http://www.mywebsite.eu
I know that the .htaccess is read because when I make a typo I have an Internal Server Error.
I also tried to redirect 404 error but this is not working.
ErrorDocument 404 https://www.mywebsite.eu/404/
You need to give full URI without domain name in pattern of RedirectMatch.
Try this rule before any other rule in site root .htaccess:
RedirectMatch 301 ^/[a-z]{2}/form/emsos-2017/?$ /
I want to redirect all pages on my site (including index) to 404 using htaccess.
Thanks in advance.
You can use this rule in root .htaccess file:
RewriteEngine On
RewriteRule ^ - [R=404,L]
The following works on newer apache:
Redirect 404
And you can add a message without creating a file like this:
ErrorDocument 404 "Hmm... There's nothing here..."
A quick question. I want to use a php file that will deliver pages based on the url. I am using htacess to deal with the error docs but my question is to do with SEO. If I redirect a 404/403 request to pageDispacher.php that then delivers the correct page will the header be a 404/403 at any point? As this is not cool. Do I need to use a rewrite rule instead?
In which case is there is a genuine 404 page how would i return a 404 header?
www.example.com > www.example.com/en/home
www.example.com/en/ > www.example.com/en/home
ErrorDocument 404 /pageDispacher.php
ErrorDocument 403 /pageDispacher.php
This is usable:
RewriteRule ^error error.php [L,QSA]
RewriteRule ^(.*)\.php$ error[L,QSA]
I am using the following code in my .htaccess:
ErrorDocument 404 error_page.php?msg=404
When I trigger a 404 error, I get a page that says this:
error_page.php?msg=404
Is there something that I am doing wrong?
Thanks
Not sure if you can pass query strings to the document designated by ErrorDocument, Something you can try is using it in conjunction with mod_rewrite:
ErrorDocument 404 /error-doc-404
ErrorDocument 405 /error-doc-405
ErrorDocument 500 /error-doc-500
RewriteEngine On
RewriteRule ^error-doc-([0-9]{3})$ /error_page.php?msg=$1 [L]
Since this is in a subdirectory off of the document root, it changes everything.
Say the subdirectory is /something/
ErrorDocument 404 /something/error-doc-404
ErrorDocument 405 /something/error-doc-405
ErrorDocument 500 /something/error-doc-500
RewriteEngine On
RewriteRule ^error-doc-([0-9]{3})$ /something/error_page.php?msg=$1 [L]
Assuming that your error_page.php file is actually in the /something/ subdirectory.