user1243851
user1243851

Reputation: 3

Apache rewriterule with regular expressions

I am trying to rewrite multiple pages like this ...

http://subdomain.domain.com/index.php?action=printpage;topic=12345.67

To this ...

http://subdomain.domain.com/index.php/topic,12345.67.html

I have unsuccessfully tried to use ...

RewriteRule ^index\.php\?action=printpage;topic=([0-9]+)\.([0-9]+)$ http://subdomain.domain.com/index.php/topic,$1.$2.html [R=302]

Apache server and my other non-related rewrites work fine. Can anyone offer any suggestions? Thanks.

Upvotes: 0

Views: 85

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

You cannot match against the query string in a RewriteRule, you need to use a RewriteCond and the % back reference:

RewriteCond %{QUERY_STRING} ^action=printpage;topic=([0-9]+)\.([0-9]+)$
RewriteRule ^index\.php$ http://subdomain.domain.com/index.php/topic,%1.%2.html? [R=302]

Upvotes: 1

Related Questions