I have several different sets of variables that can be alhpa numeric.
If I comment out any two sets the other will work. Only one set will work but need all three to work.
First set is only one level:
domain.com/index.php?var1a=var1a
The second set can be one, two or three levels:
domain.com/index.php?var2a=var2a
domain.com/index.php?var2a=var2a&var2b=var2b
domain.com/index.php?var2a=var2a&var2b=var2b&var2c=var2c
The third set can be one, two or three levels:
domain.com/index.php?var3a=var3a
domain.com/index.php?var3a=var3a&var3b=var3b
domain.com/index.php?var3a=var3a&var3b=var3b&var3c=var3c
htaccess file looks like this:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?var1a=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?var1a=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?var2a=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?var2a=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?var2a=$1&var2b=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?var2a=$1&var2b=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)([a-zA-Z0-9_-]+)/$ index.php?var2a=$1&var2b=$2&var2c=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?var2a=$1&var2b=$2&var2c=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?var3a=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?var3a=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?var3a=$1&var3b=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?var3a=$1&var3b=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?var3a=$1&var3b=$2&var3c=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?var3a=$1&var3b=$2&var3c=$3 [L]
After testing I understand why this won’t work but cannot work out how to define the different sets.
Based on the comments, above, the search URLs are the easiest to accommodate since they start with a consistent /search, so that rule will go first:
/?makes the trailing slash optional so you can match with or without on the same rule.That leaves affiliate and post links. Assuming post links have a variety of starting terms (categories), unlike “search”, we need to distinguish those from usernames. Usernames only have one level, though, so first we can capture any two or three level URLs as post links:
Finally, for single level URLs to distinguish between categories and usernames, it’s probably the case that there are a limited number of known categories that change infrequently while usernames are more numerous and more prone to change. So, you need a lookup method for categories and then default any that don’t match to be usernames.
To lookup categories, you need to use a
RewriteMap. You’ll need to look through the RewriteMap documentation to determine which type will work best for your situation, but it would end up something like this:I haven’t used RewriteMaps myself or RewriteConds of that particular format, so it may need tweaking, but the idea is that the RewriteCond says to match the incoming path against a capture of everything up to the comma (
^([^,]+)) and then to match the categorymap against that captured pattern (\1).