Redbox
Redbox

Reputation: 1477

apache mod_rewrite non-existing file to something

i have rule like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/show_video.php?id=[a-zA-Z0-9_-]+/(.*)$ /video/$1 [R]
</IfModule>

i want to redirect: http://www.domain.com/show_video.php?id=8 to http://www.domain.com/video/8/

show_video.php does not exist on the server.

how do i do that? my rule does not work.

Upvotes: 0

Views: 210

Answers (2)

Cyclonecode
Cyclonecode

Reputation: 30051

You need to check the QUERY_STRING in a rewrite condition, here is an example that probably would work:

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^show_video\.php$ /video/%1? [R=302,L] 

Upvotes: 2

Jon Lin
Jon Lin

Reputation: 143906

You need to match against the query string using a RewriteCond and the %{QUERY_STRING} variable, then use the %1 to backreference the match:

RewriteCond %{QUERY_STRING} ^id=([a-zA-Z0-9_-]+)$
RewriteRule ^/?show_video.php$ /video/%1/? [R,L]

Upvotes: 1

Related Questions