I am trying to use htaccess Rewrite Rules to map multiple GET variables, but not all variables are required. I ordered the variables so that x is always required, if y is given, then z must be set, etc. Therefore, I need the mappings to look like this:
example.com/section/topic/sub
to display on
example.com/?x=section&z=topic&y=sub
However, the following code causes an internal error, but if I have only one Rewrite rule, it works.
Options +FollowSymLinks
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ([^/]+)/? [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ ?x=$1&z=$2&y=$3&r=$4 [NC,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ ?x=$1&z=$2&y=$3 [NC,L]
RewriteRule ^([^/]+)/([^/]+)$ ?x=$1&z=$2 [NC,L]
RewriteRule ^([^/]+)$ ?x=$1 [NC,L]
</IfModule>
I also need to make sure that the url can have trailing /, but does not require it.
As you probably can tell, I'm new to htaccess.
thanks
source
share