URL Rewrite On.htaccess
I am trying to make a rewrite rule that will understand
and
http://example.com/test.php?t=1234
This is what I have now and it doesn't work:
RewriteEngine on
RewriteRule ^test?t=([^/\.]+)/?$ http://mywebsite.com/test/$1 [L]
Can someone give me a hand?
+3
source to share
2 answers
Your rewriteRule is reversed in that you have to match on the left that you want the clean url to look and rewrite on the right where the file is on the server. But even if it wasn't the other way around, you would have to escape the question mark in RegExp. But since it's the opposite, you should use something closer to:
RewriteEngine on
RewriteRule ^test/(.*) test.php?t=$1 [L]
+2
source to share
Try:
RewriteEngine On
RewriteCond %{THE_REQUEST} /test.php\?t=([^&\s]+) [NC]
RewriteRule ^test.php$ /test/%1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/([^/]+)/?$ /test.php?t=$1 [QSA,L,NC]
The query string is not part of the match in the rewrite rule directive, use the% {QUERY_STRING} or% {THE_REQUEST} variables to match the query string.
+1
source to share