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
Related
Recently my site got hacked, and tons of pages were generated. Most of them end with strings like ?_t=77, ?_t=97, and ?_t=56 etc. Basically, the ?_t= part is common in all of them.
How do I create a .htaccess rule to redirect all the links with ?_t= to home?
Some redirects I've already created:
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>
Thanks
With your shown attempts/samples, please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
##making your Rewrite engine ON here.
RewriteEngine On
##Rewriting urls with ending with ?_t=digits to home page here.
RewriteCond %{QUERY_STRING} ^_t=\d+/?$ [NC]
RewriteRule ^ / [R=301,L,QSD]
##Rewriting home page url to index.php here.
RewriteRule ^/?$ index.php [QSA,L]
###put your rest of htaccess Rules from here onwards.
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>
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>
I'm trying to setup a 301 redirect for the following link:
https://www.domain.de/aaa/bbb/
and i wanna redirect it to:
https://www.domain.de/ccc.html
and thats what i already tried:
Redirect 301 /aaa/bbb/ https://www.domain.de/ccc.html
RewriteRule ^aaa/bbb/$ /ccc.html? [L,R=301]
and
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /aaa/bbb/ /ccc.html
</IfModule>
none of them worked for me. Any hints for me?
You can use this:
RedirectMatch /aaa/bbb/(.+)$ https://example.com/$1.html
Short explanation :
The regex capture-group (.+) captures everything after /aaa/bbb/ and saves the captured value in $1 variable and then we use the $1 in the destination url.
This is doing a temporary (302 default status) redirection from /aaa/bbb/foobar/ to /foobar.html . If you want a permanent (301) url redirecton, simply add a 301 status code to the directive ie: RedirectMatch 301 pattern destination .
I have this htaccess code which works fine to redirect all pro.php requests to index.php:
Redirect 301 /de/pro.php /de/index.php
Redirect 301 /en/pro.php /en/index.php
Redirect 301 /fr/pro.php /fr/index.php
BUT, is there an elegant possibility with just one line of code for manyfold directories /de /en /fr /.. ?
You can use RedirectMatch :
RedirectMatch ^/(.+)/((?!index).+)\.php$ /$1/index.php
I found a website linking to my site with www.example.com/home.html which doesn't exist. I tried to set up a redirect:
Redirect 301 /home.html //www.example.com
But it redirects to www.example.com/www.mysite.com
Can I use the Redirect, or do I have to do a rewrite?
please use rewrite rule:
first:
Options +FollowSymLinks
RewriteEngine On
and then
RewriteRule ^home.html$ http://www.example.com/ [r=301,nc,L]
Redirect 301 /home.html //www.example.com
In this case, the target URL (starting with a slash) is seen to be root-relative to the current scheme/host. Providing you have a DirectoryIndex setup appropriately, you can just redirect to /.
For example:
Redirect 301 /home.html /