: Htaccess rewrite ignore 2 strings I have the following rewrite rule to rewrite my old to new URLs: RewriteCond %{REQUEST_URI} !^/activity.*$ [NC] RewriteRule ^(.*)/([0-9]+)/$ //S/ [R=301,L] It
I have the following rewrite rule to rewrite my old to new URLs:
RewriteCond %{REQUEST_URI} !^/activity.*$ [NC]
RewriteRule ^(.*)/([0-9]+)/$ //S/ [R=301,L]
It must also ignore /members, not only /activity.
How can I achieve that?
More posts by @Sarah324
2 Comments
Sorted by latest first Latest Oldest Best
You can do this by adding another condition.
RewriteCond %{REQUEST_URI} !^/members [NC]
RewriteCond %{REQUEST_URI} !^/activity [NC]
RewriteRule ^(.*)/([0-9]+)/$ //S/ [R=301,L]
Or, sometimes simpeler, use the OR of a regex:
RewriteCond %{REQUEST_URI} !^/(members|activity) [NC]
RewriteRule ^(.*)/([0-9]+)/$ //S/ [R=301,L]
I've removed the .*$ from your lines. That piece ment "any character (.*) untill the end ($) of the line. By removing that, you get the exact same effect, but more readable and I'm guessing it requires less resources because the regex is simpler.
You can just add another RewriteCond directive:
RewriteCond %{REQUEST_URI} !^/activity
RewriteCond %{REQUEST_URI} !^/members
RewriteRule ^(.*)/([0-9]+)/$ //S/ [R=301,L]
Multiple RewriteCond directives are AND'd together by default. The OR flag can be used if required. I've removed the NC flag - unless you specifically need a case-insensitive match. As mentioned in comments, I've also simplified your regex slightly. .*$ says that the string can have any characters after the word "/activity", which is the same as a string that is simply prefixed with "/activity".
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.