Reputation: 11
I can't figure our RewriteRule so I've tried RedirectMatch. I need to match to a folder /2018/
and all other sub-folders but I do not want to redirect /2018/speakers/
or /2018/events/
RedirectMatch 301 ^/2018/$^(speakers|events)($|/) https://example.com/north-america
Doesn't seem to work and I really can't figure out how to exclude after an include. Thanks for any help!
If it must be Rewrite Rule here is the rest of the top portion. I need to do this for multiple years like 2017, 2016 etc so maybe this is the best way to do it.
# Force https
RewriteCond %{HTTP:X-Pagely-SSL} off
RewriteRule ^(.*)$ https://example.org/$1 [R=301,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Upvotes: 1
Views: 154
Reputation: 5129
You can use RewriteCond
to exclude some URLs
RewriteCond %{REQUEST_URI} !^/2018/(speakers|events)
RewriteRule ^/?2018/(.+) https://example.com/north-america/$1 [R=301,QSA,L]
Line 1: if the request uri is not starting with /2018/speakers
or /2018/events
Line 2: if the request uri is starting with /2018/
, then redirect to https://example.com/north-america/
permanently. $1
is the backreference to (.+)
.
Upvotes: 2