George Peter
George Peter

Reputation: 69

Apache Condition - Different Rewrite Based on Existence of Query String

I have the following rules:

RewriteCond %{REQUEST_URI} ^/33\.php$ [NC]
RewriteRule ^33.php "/api.php" [NC,L]

I want to rewrite /33.php to /api.php, and anything other than that, such as /33.php?foo=bar to get a 404. How could I achieve that? Thanks.

Upvotes: 1

Views: 41

Answers (1)

user2493235
user2493235

Reputation:

You can do it as shown below. The query string is in its own variable.

# Rewrite /33.php with no query string to /api.php
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^33\.php$ /api.php [NC,L]

# Return 404 for /33.php?anything
RewriteRule ^33\.php$ - [NC,R=404,L]

Upvotes: 1

Related Questions