Friday, May 5, 2017

redirect everything with exceptions

Leave a Comment

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.

1 Answers

Answers 1

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.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment