.htaccess rewritecond rewrite case level 2 folder = info
I wanted to set .htaccess
to overwrite:
example.com/bla/info/
to
example.com/info/index.php?q=bla
example.com/bla/info/txt/
to
example.com/info/index.php?q=bla&t=txt
I need the browser to still display:
example.com/bla/info/txt/
I didn't want to overwrite the level 2 rewrite, for example:
example.com/bla/xxx/
or
example.com/ccc/zzz/aaa/
but
example.com/silly/info/
will work the same as
example.com/strange/info/mytxt/
Did it make sense?
Any help?
source to share
If you start your template with ^ and end it with $, the rule will only apply if the entire string matches.
RewriteRule ^/bla/info/$ /info/index.php?q=bla
RewriteRule ^/bla/info/txt/$ /info/index.php?q=bla&t=txt
If you use, do not use the [R] option, the URL displayed in the browser will be the one entered by the user.
Are you trying to make it versatile? If so, you can use regex type matching and variable substitution. To make "bla" match any line up to the next forward slash (/), use
([^/]+)
in your template and reference it with $ 1 in your replacement.
RewriteRule ^/([^/]+)/info/$ /info/index.php?q=$1
RewriteRule ^/([^/]+)/info/([^/]+)/$ /info/index.php?q=$1&t=$2
I recommend Apache's web pages on mod_rewrite for more information.
[Edit. Fixed rules to not include the hostname in the template because the original poster was found.]
- BMB page
source to share