1

I have the following RewriteRule in place. This rewrites everything that starts with mac, linux or windows:

RewriteCond $1 ^(mac|linux|windows) [NC]
RewriteRule ^(.*)$ /index.php/site/index/$1 [L]

Unfortunately this also rewrites /mac/test/testing. How can I prevent it from applying if there is another segmend after /mac?

user43365
  • 21
  • 3

1 Answers1

1

So I found the solution:

RewriteCond $1 ^(linux|mac|windows)($|\/)$ [NC]
RewriteRule ^(.*)$ /index.php/site/index/$1 [L]

RewriteCond $1 ^(linux|mac|windows)/category/(.*)$ [NC]
RewriteRule ^(.*)$ /index.php/site/category/$1 [L]

RewriteCond $1 ^(app|download)/(.*)$ [NC]
RewriteRule ^(.*)$ /index.php/site/$1 [L]

Note the $ sign at the end of the first line. I am not sure if ($|\/) is the correct method to make a trailing slash optional but it works. Any advice?

Edit: There is actually a simpler way to handle the trailing slash.

RewriteCond $1 ^(linux|mac|windows)/?$ [NC]
RewriteRule ^(.*)$ /index.php/site/index/$1 [L]
user43365
  • 21
  • 3
  • The `RewriteCond` directives are superfluous, you can write it like this: `RewriteRule ^(linux|mac|windows)/?$ /index.php/site/index/$1 [NC,L]` – MrWhite Aug 08 '20 at 11:05