munjal
munjal

Reputation: 1404

htaccess rewrite problem

I am new on stackoverflow.com and also in .htaccess.

I just ask one thing:

RewriteCond %{QUERY_STRING} ^event_id=156$
RewriteRule ^test1.php?$ /htaccess_test/test.php

RewriteCond %{QUERY_STRING} ^event_id=154$
RewriteRule ^test1.php?$ /htaccess_test/test2.php

I just want to merge these two rewrite rules because i have lots of these kinds of rules. So i just want to wrap up these things instead of writing two more lines each and every time for new event_id.

Can you please tell me how can i write this thing?

Upvotes: 0

Views: 130

Answers (2)

anubhava
anubhava

Reputation: 784938

Try this combined code in your .htaccess file:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^event_id=(156|154)$ [NC]
RewriteRule ^test1\.php/?$ /htaccess_test/test.php [NC,L]

Upvotes: 0

Michael Bai
Michael Bai

Reputation: 586

As I see, you want to redirect test1.php to test.php or test2.php due to different event_id. I don't think you can merge these two rules because the destination is not the same due to different conditions. But you can merge the different event_id to the same condition, like you want event_id 156 157 158 to redirect to test.php, want 152 153 154 to redirect to test2.php, you can write this way:

RewriteCond %{QUERY_STRING} ^event_id=156$
RewriteCond %{QUERY_STRING} ^event_id=157$
RewriteCond %{QUERY_STRING} ^event_id=158$
RewriteRule ^test1.php?$ /htaccess_test/test.php

RewriteCond %{QUERY_STRING} ^event_id=152$
RewriteCond %{QUERY_STRING} ^event_id=153$
RewriteCond %{QUERY_STRING} ^event_id=154$
RewriteRule ^test1.php?$ /htaccess_test/test2.php

Hope this help you more or less.

Upvotes: 2

Related Questions