Mobile app version of vmapp.org
Login or Join
Sarah324

: 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

@Sarah324

Posted in: #Htaccess #ModRewrite

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Sarah324

2 Comments

Sorted by latest first Latest Oldest Best

 

@Courtney195

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.

10% popularity Vote Up Vote Down


 

@Ann8826881

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".

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme