I am trying forward /test/12 to test?var=12 using htaccess
I have set up my .htaccess
file as follows:
RewriteEngine on
RewriteRule ^test/(.+)$ test?$1 [L]
Can somebody point me in the right direction?
Thanks
I am trying forward /test/12 to test?var=12 using htaccess
I have set up my .htaccess
file as follows:
RewriteEngine on
RewriteRule ^test/(.+)$ test?$1 [L]
Can somebody point me in the right direction?
Thanks
2
Answers
My mistake was adding the .htaccess in the wrong directory. I should have added it in the parent directory, but I was adding
^test/(.+)$ test?$1
in thetest
directory.I wanted to take the full query after the trailing slash in the url, so the rule I used in the parent directory was
RewriteRule ^(.*)$ test.php?$1
. This in turn caused a circular loop so I redirected to a directory within the parent so the final working rule that took the final part of the url string after the/
and forwarded it as a variable totest.php?$1
looked like this.RewriteRule ^(.*)$ test/test.php?$1
[^/]
means “any character that’s not a slash”. Naturally this means that “text” cannot contain any slashes, but your URL will be matched correctly.Also note the
[B]
which is one of many options you can add to a rewrite rule.[B]
means that any&
s and some other characters will be escaped.now in your
test.php
will output for url
http://localhost/test/123/456/asdf
: