user3681788
user3681788

Reputation: 221

.htaccess rewriterule not working properly

I'm trying to mask a URL that looks like this:

http://example.com/test-test-test-test/item.swf?id=122

...to display the content of this URL, while passing on the GET parameter:

http://example.com/images/item.swf?id=122

This is because item.swf does not actually exist in the test-test-test-test directory. I'm currently using this, however it is not working:

RewriteRule ^test-test-test-test/item\.swf\?id=([0-9]+)$ images/item\.swf\?id=$1 [L]

This .htaccess file is in my root folder.

Upvotes: 0

Views: 77

Answers (2)

Meeuuuhhhh
Meeuuuhhhh

Reputation: 388

RewriteRule regex isn't on query parameters, for this, you can use the [QSA] flag:

"When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined."

Example :

RewriteRule ^test-test-test-test/item\.swf$ images/item.swf [L,QSA]

Hope it helps.

Upvotes: 0

arco444
arco444

Reputation: 22881

Try this instead:

RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^test-test-test-test/item\.swf /images/item.swf?id=%1 [R,L]

Upvotes: 1

Related Questions