Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect everything with exceptions

I am looking for quite some time here to find something similar, but I am unable to find what I am looking for.

I would like to redirect an old Project discarded Project to a new one, they are only partly similar and I would like to redirect the matches, and afterwards everything else, while removing every

I think I remembere that htaccess Rules are worked one after another, so I can simply add 301's above the redirect everything else, but it turns out that this code

RewriteEngine On

Redirect 301 /match1.html https://www.domain.tld/match1/
Redirect 301 /match2.html https://www.domain.tld/match2/
Redirect 301 /match3.php&page=6 https://www.domain.tld/match3/?

RewriteBase /
RewriteRule .*? https://www.domain.tld/? [R=301,L]

redirects simply everything directly to https://www.domain.tld/

The Old Project mas completely manual work with 450+ static html pages and another ~100 php files, so I hope there is a more simple way that creating a huge .htaccess to do this.

like image 861
Caylean Avatar asked Oct 29 '22 08:10

Caylean


1 Answers

Your rule redirecting everything to https://www.domain.tld/ because of your last rule, and for redirecting enbloc you can use regular expression for match try with below,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ https://www.domain.tld/$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ https://www.domain.tld/$1/ [R=301,L]

If there are other certain patterns please provide them and I am assuming you are using the rules in root .htaccess or respective directory.

like image 179
Abhishek Gurjar Avatar answered Jan 02 '23 21:01

Abhishek Gurjar