Redirect all with exceptions

I am looking for quite a while to find something similar, but I cannot find what I am looking for.

I would like to redirect the old project with the dropped project to the new one, they are only partially similar, and I would like to redirect the matches, and then everything else, deleting each

I think I remember that the htaccess rules work one by one, so I can just add 301 above the redirect to 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] 

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

The old project fully manages working with 450+ static html pages and ~ 100 more php files, so I hope there is an easier way to create a huge .htaccess for this.

+5
source share
1 answer

Your rule redirects everything to https://www.domain.tld/ because of your last rule, and for redirecting enbloc you can use a regular expression to check for compliance 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 specific patterns, please provide them, and I assume that you are using the rules in the .htaccess root directory or the corresponding directory.

+2
source

Source: https://habr.com/ru/post/1267059/


All Articles